List-comprehension-like extensions in normal for loops

March 1, 2008
10:24 p.m.
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 line: 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.
6225
Age (days ago)
6227
Last active (days ago)
2 comments
3 participants
participants (3)
-
Adam Atlas
-
Eyal Lotem
-
Josiah Carlson