[ x for x in xrange(10) when p(x) ]

Alex Martelli aleax at mail.comcast.net
Thu Nov 10 04:27:40 CET 2005


bonono at gmail.com <bonono at gmail.com> wrote:

> Hi,
> 
> I am wondering if there is such a thing, as python is moving away from

This becomes a valid list comprehension by writing 'if' instead of
'when'.

> FP functions like dropwhile/takewhile etc.

No way -- the itertools module is and remains a PRECIOUS resource.  If
you want an iterator rather than a list, itertools.ifilter is quite
appropriate here.


Alex



More information about the Python-list mailing list