[Python-ideas] List-comprehension-like extensions in normal for loops

Adam Atlas adam at atlas.st
Sat Mar 1 23:24:37 CET 2008

How about letting ordinary for loops contain multiple "for"s and  
optionally "if"s like in list comprehensions and generator  
expressions? For example, on a site I was just looking at, it had the  
     for record in [ r for r in db if r.name == 'pierre' ]:
which could instead be:
     for record in db if record.name == 'pierre':

And of course there could be much more complex ones too. I know you  
could just do "for x in <some generator expression>" and get the same  
effect and roughly the same speed, but I think this looks a lot nicer,  
and it would make sense to have this sort of consistency across the  
multiple contexts in which "for" can be used.

More information about the Python-ideas mailing list