View Single Post
Old 01-09-2023, 08:59 AM   #469
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,522
Karma: 8065528
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is there a function that sorts a list into a user-defined order?

Context: I have a text column that may return results in a list-string like "foo, bar, foo, foo, foobar."

Using Action Chains, I'd like to:
a) Sort the entries in a user-defined order (e.g. "foobar, bar, foo, foo, foo)
b) Select the first item of this sorted list

And then replace the string with that.

(Additional context: When FanFicFare downloads an anthology of multiple fics, it concenates all the ratings into an unsorted string like "General Audiences, Mature Audiences, Explicit, Teen and Up Audiences, Not Rated." In order, I want to pick the first of Explicit > Mature > Teen > General > Not Rated.)
No. The only way to do it that I can think of is to make a list containing all possible items, then loop through that list using for. If the actual list contains the current item then add it to the result list, otherwise skip it. Something like this:
Code:
program:
	possibles = 'Explicit, Mature, Teen, General, Not Rated';
	actuals = 'foo, Mature, Teen, Explicit';

	answer = '';
	for item in possibles:
		if '^' & item & '$' inlist actuals then
			answer = item;
			break
		fi
	rof;
	answer
Quote:
edit: can I check just one column with a first_non_empty?
I don't understand. Are you asking if you can have only one rule? Yes.

Last edited by chaley; 01-09-2023 at 09:04 AM. Reason: Removed incorrect text in the last sentence.
chaley is offline   Reply With Quote