Quote:
Originally Posted by Noughty
It's all english. How about extracting values instead or removing them? Like listing the values I want to keep and removing all others.
|
Use something like the following:
Code:
def evaluate(self, formatter, kwargs, mi, locals):
# Tags is a multiple text field, so it is already split
tags = set(mi.get('tags', []))
# Shelf is a multiple text field, so it is already split
shelf = set(mi.get('#shelf', []))
# items that must be in the result
must_have = set(['foo', 'bar', 'somethingElse', 'Comics',
'andSoOn', 'until I get tired', 'of adding things'])
# combine tags and shelf together
ts = tags | shelf
# get the items in the combined tags and shelf that are also in must_have
res = must_have & ts
return ', '.join(sorted(res))
The line "must_have & ts" returns a set containing items that are in both must_have and ts. This effectively extracts items in must_have from the set ts.
As for your question about functions in python, the definitive source is the python manual. It can be (is!) overwhelming. However, all the functions we have been using here are described in the section
http://docs.python.org/library/stdty...-set-frozenset.