[NCLUG] help w/ python list comprehension

Sean Reifschneider jafo at tummy.com
Tue Aug 27 20:37:00 MDT 2013


On 08/20/2013 07:55 PM, Michael Cullerton wrote:
> # if an item has all the filter_tags, append it to items_by_tag

Ah, I mis-read the code in regard to this.  You can change the filter
function to achieve that as below.

I also made some argument errors, so here's a corrected one:

    filter = set([x.lower() for x in tags if x])

    def any_matching_tags(search):
        return not (filter - set([x.lower() for x in search]))

    return [x for x in items if any_matching_tags(x.tags)]

Sean


More information about the NCLUG mailing list