On Tue, Jun 29, 2021 at 01:37:59AM +0100, Rob Cliffe via Python-ideas wrote:

>     for i in range(0, 10): if i not in range(2, 8):
>         <do stuff>
> # This is arguably slightly easier to read than having two separate 
> lines,

"Arguably" is an understatement.

> as it puts both aspects of a single concept ("what values of i do 
> I loop over?") together.

I would consider it two concepts: (1) you're looping over the values 
range(0, 10) and (2) skipping over values in range(2, 8).

Until we reach the bottom of the block, we can't be sure that the 
condition isn't

    if i not in range(2, 8): ...
    else: ...

which by the way suggests that this suggested syntax would be ambiguous:


    for i in seq: if condition:
        block
    else:
        block

Does the `else` partner the `for` or the `if`?


-- 
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/TYJWGZYSUYVXPWWMINNRWHGBFFDUK6N3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to