While this looks attractive to me, and it's definitely better to change statement and comprehension syntax at the same time, this makes the comprehension ambiguous to human parsing.

[f(x) for x in list if x > 10] basically can be read as

for x in list:
    if x > 10:
        f(x)

This kind of interpretation becomes critical if you nest more than two levels. But [f(x) for x in list while x < 10] could read either as

for x in list while x < 10:
    f(x) 

which is how you want it to be read, or (more in line with earlier list comp habits):

for x in list:
    while x < 10:
        f(x)

which would be totally wrong.

I don't think this is a very serious problem (certainly not for the interpreter), but it's a stumbling block.

On Mon, Jul 1, 2013 at 10:03 PM, Jan Kaliszewski <zuo@chopin.edu.pl> wrote:
2013-07-02 00:44, Oscar Benjamin wrote:
[...]

Having a while clause on for loops is not just good because it saves a
couple of lines but because it clearly separates the flow control from
the body of the loop (another reason I dislike 'break if'). In other
words I find the flow of the loop

    for p in primes() while p < 100:
        print(p)

easier to understand (immediately) than

    for p in primes():
        if p >= 100:
            break
        print(p)

+1

Cheers.
*j


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas