[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Tue Jun 25 22:51:06 CEST 2013


Hi,
I suggested the very same 'while in a comprehension/generator expression'
back in January:
http://mail.python.org/pipermail/python-ideas/2013-January/018969.html

There were many very useful responses suggesting alternative syntax (that
I'm using now).
The proposal itself was dismissed with the logic that comprehensions can
currently be translated directly into explicit for loops, e.g.:

[x for x in items if x!=0]

equals:

result=[]
for x in items:
    if x!=0:
        result.append(x)

This equivalence is considered *very* important and the while statement
would break it:

[x for x in items while x>0]

does *not* translate into:

for x in item:
    while x>0:
        result.append(x)

So, as long as you can't come up with syntax that translates properly,
there's no chance of getting it accepted.

Best,
Wolfgang




More information about the Python-ideas mailing list