[ x for x in xrange(10) when p(x) ]
bonono at gmail.com
bonono at gmail.com
Thu Nov 10 07:56:34 EST 2005
Peter Hansen wrote:
> (I say "readable or somehow better" since you stated in another post "I
> just try to use list/generator expression when possible" but you didn't
> explain your reason for doing so. I assume you have some reason other
> than arbitrary whim.)
The reason is simple:
I found it easier to read for me and using list/generator expression
helped me uncover a number of subtle bugs comparing with an imperative
approach.
on its own :
takewhile(lambda x: condition(x), some_generator) is not very much
difference than(well, still more things to type)
(x for x in some_generator when condition(x))
but when I have a number of them in the same expression, the
takewhile/dropwhile becomes to add up.
More information about the Python-list
mailing list