[Python-ideas] List-comprehension-like extensions in normal for loops
Eyal Lotem
eyal.lotem at gmail.com
Sat Mar 1 23:57:08 CET 2008
How about just nesting the for's/if's?
for record in db:
if record.name == 'pierre':
...
Isn't that the one obvious way to do it?
On Sun, Mar 2, 2008 at 12:24 AM, Adam Atlas <adam at atlas.st> wrote:
> 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.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
More information about the Python-ideas
mailing list