For loop comprehensions

Westley Martínez anikom15 at
Sat Feb 12 00:47:08 CET 2011

On Fri, 2011-02-11 at 15:10 -0800, Benjamin S Wolf wrote:
> It occurred to me as I was writing a for loop that I would like to
> write it in generator comprehension syntax, eg.
>   for a in b if c:
> rather than using one of the more verbose but allowable syntaxes:
>   for a in (x for x in b if c):
>   for a in b:
>     if not c: continue
> Python 3.1 does not support "for comprehensions", and a few cursory
> searches of PEPs and this list don't turn up anything. I like the idea
> enough to suggest it though I'm unfamiliar with the PEP/feature
> request process (PEP 1 pointed me here). What do other people think?
> --Ben
No, too confusing. Then people'll want compound loops e.g.:

for a in b if c while d else return x:
    print('Ha ha I'm so clever!')

More information about the Python-list mailing list