[NCLUG] help w/ python list comprehension

Mike Cullerton michaelc at cullerton.com
Wed Aug 21 09:54:31 MDT 2013


On Aug 20, 2013, at 8:53 PM, Stephen Warren <swarren at wwwdotorg.org> wrote:

> missing = [tag for tag in filter_tags and not tag in item.tags]

That is cool.

Here's what I ended with. And yes, it was mainly for learning.

    for item in items:
        missing = False
        for tag in tags:
            # do we have a tag (ignore tag == '')
            # can we find it in item.tags
            if tag and not tag.lower() in [tag.lower() for tag in item.tags]:
                missing = True
                break
        if not missing: items_by_tag.append(item)
    return items_by_tag





More information about the NCLUG mailing list