Is there a more elegant way to spell this?
jpiitula at ling.helsinki.fi
Tue Jan 27 15:25:21 CET 2015
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):
If you mean literally some_predicate, then perhaps this.
for x in seq:
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.
More information about the Python-list