[Python-Dev] comprehension abbreviation (was: Adding any() and all())

Jim Jewett jimjjewett at gmail.com
Fri Mar 11 20:03:17 CET 2005


> Ping's suggested list comprehension abbreviation, i.e.:

>    [x in seq if x] == [x for x in seq if x]

> might help.

Note that the last x shouldn't have to be x.

    [x in seq if f(x)] 

is by far my most common syntax error, and 

    [x for x in seq if f(x)]

is always what I want instead.

More information about the Python-Dev mailing list