For loop comprehensions

Ian Kelly ian.g.kelly at
Fri Feb 11 18:59:52 EST 2011

On Fri, Feb 11, 2011 at 4:47 PM, Westley Martínez <anikom15 at> wrote:
> 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!')

I've yet to see anybody arguing for while loops to be nested like
that, but we already allow nested for loops in comprehensions and
generator expressions:

[(x, y) for x in a for y in b if c(y)]

Why not allow the same thing in for-loop conditions?  I think that
anything that makes the language syntax more consistent is good.


More information about the Python-list mailing list