Steven D'Aprano writes: > We really are spoiled for choice here. We can write any of these: > > # Option 1 > for spam in sequence: > if predicate(spam): > process(spam)
# Option 1.5 for spam in sequence: if not predicate(spam): continue process(spam) This saves an indent level. > # Option 2 > for spam in filter(predicate, sequence): > process(spam) > > # Option 3 > for spam in (spam for spam in sequence if predicate(spam)): > process(spam) > > > Adding a fourth option: > > for spam in sequence if predicate(spam): > process(spam) > > saves absolutely nothing except a line and an indent level, neither > of which are in short supply, and gains nothing in readability over > Option 1. -- http://mail.python.org/mailman/listinfo/python-list