View Single Post
Old 06-04-2023, 06:52 AM   #631
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,461
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
...

This removes the 'Culture & Regions' items from split_tags, extracts the lastmost item, and merges them back in.

However, it only works with one item. After splitting the culture_tags list with ',', how do I process each item separately?

Example: Fiction.Cultures & Regions.Canada.Western Canada, Fiction.Cultures & Regions.Metis, Fiction.Historical Fiction
Preferred result (after sorting): Historical Fiction, Metis, Western Canada
Actual result: Historical Fiction, Metis
It is hard to understand what you are trying to do. What you say the code does and what the code actually does are different.

Reading what you say and the code, it appears that:
  • if a tag contains the item "Cultures & Regions" then you want the last item.
  • otherwise you want all items split into individual tags.
However, the examples don't agree with this. Your code will include both the "Fiction" and "Historical Fiction" of "Fiction.Historical Fiction" while your example output does not. Which is right?

This template does one version of what you might be asking for.
Code:
program:
	tags = 'Fiction.Cultures & Regions.Canada.Western Canada, Fiction.Cultures & Regions.Metis, Fiction.Historical Fiction, Fiction.Bar.Mumble';
	new_tags = '';

	for t in tags:
		if '\.Cultures & Regions\.' in t then
			nt = list_item(t, -1, '.')
		else
			nt = re(t, '\.', ',')
		fi;
		new_tags = list_union(new_tags, nt, ',')
	rof;
	list_sort(new_tags, 0, ',')
The output is
Code:
Bar, Fiction, Historical Fiction, Metis, Mumble, Western Canada
chaley is offline   Reply With Quote