[Python-ideas] filter-only list comps

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 26 00:40:22 CET 2010


spir wrote:

> But the analog does not apply to filter-only list comps:
> 	[x in numbers if x%2==1]	# SyntaxError

If you were allowed to say that, you should also be
able to say

    [x in numbers]

but this already has a meaning as an ordinary list
constructor.

Requiring the word 'for' to appear in an LC ensures
that there is never any ambiguity.

However, it might be possible to phrase it another
way, e.g.

   [x from numbers if x%2==1]

-- 
Greg



More information about the Python-ideas mailing list