Iterating across a filtered list
Tue Mar 13 20:35:39 CET 2007
"Drew" <olsonas at gmail.com> writes:
> You're exactly on the mark. I guess I was just wondering if your first
> example (that is, breaking the if statement away from the iteration)
> was preferred rather than initially filtering and then iterating.
I think the multiple statement version is more in Python tradition.
Python is historically an imperative, procedural language with some OO
features. Iterators like that are a new Python feature and they have
some annoying characteristics, like the way they mutate when you touch
them. It's usually safest to create and consume them in the same
place, e.g. creating some sequence and passing it through map, filter, etc.
More information about the Python-list