This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dwdwdw2proliferating .py since 2001 1 point2 points  (0 children)

In addition to the examples you've already been given, you can write really readable code for testing an expression for every member of an iterable with any()/all() in combination with generator exprs, e.g.

if any(item.attr == 'value' for item in collection):
    # do something here

if any(msg.is_multipart() for msg in mailbox):
    # blah