Neal Becker writes: > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]:
If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) If you mean literally some_predicate, then perhaps this. if some_predicate: for x in seq: handle(x) Unless you also have in mind an interesting arrangement where some_predicate might change during the loop, like this. for x in [_ for _ in seq if some_predicate]: ... some_predicate = fubar(x) ... Then I have nothing to say. -- https://mail.python.org/mailman/listinfo/python-list