Proposed new syntax

Marko Rauhamaa marko at pacujo.net
Fri Aug 11 09:02:51 EDT 2017


Serhiy Storchaka <storchaka at gmail.com>:

> 10.08.17 17:28, Steve D'Aprano пише:
>> What would you expect this syntax to return?
>>
>> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]
>
> I would expect it to be equivalent to the following code:
>
>     result = []
>     for x in (0, 1, 2, 999, 3, 4):
>         while x < 5:
>             result.append(x + 1)

And I would expect this:

    result = []
    for x in (0, 1, 2, 999, 3, 4):
        if not x < 5:
            break
        result.append(x + 1)


Marko



More information about the Python-list mailing list