[Python-ideas] About list comprehension syntax

Josiah Carlson jcarlson at uci.edu
Thu May 31 06:30:55 CEST 2007


Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Arnaud Delobelle wrote:
> 
> > Why not just drop the 'x for' at the start of a 'filter  
> > comprehension' (or generator expression)?  Thus (3) could be written  
> > more simply as:
> > 
> > (3') [x in L if p(x)]
> 
> It would be very nice, but could be difficult to parse,
> because there's no clue you're not looking at a normal
> list constructor until you get to the 'if'.

Even then it's not terribly clear except that there's a missing 'else'
clause for conditionals...

    y = [x in L if p(x) else None]

Will create a list of a single value in Python 2.5 .

 - Josiah




More information about the Python-ideas mailing list