[Python-ideas] filter-only list comps

spir denis.spir at gmail.com
Fri Feb 26 09:50:48 CET 2010

On Thu, 25 Feb 2010 18:35:17 -0500
Fred Drake <fdrake at acm.org> wrote:

> On Thu, Feb 25, 2010 at 6:40 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> >  [x from numbers if x%2==1]
> I like this, but it has the same readability issue I noted for cases
> where decomposition is used:
>     [(k, v) from somedict.items() if condition(v)]

You're right on readability. On the other hand, unpacking is a common practice in python.
Can this be mis-interpreted? (I mean, is it ambiguous?)
Also note that custom iterators can generate "items" of arbitrary complexity. This point cannot be addressed by the syntax for comprehensions.


la vita e estrany


More information about the Python-ideas mailing list