Quote:
Originally Posted by ownedbycats
...
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