Proposed new syntax
Mikhail V
mikhailwas at gmail.com
Thu Aug 10 22:54:29 EDT 2017
>
> What would you expect this syntax to return?
>
> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]
>
Nice question BTW
I'd suppose two possible outcomes:
a) It will behave exactly the same as if there was "if" instead of "while"
so [1, 2, 3, 4, 5].
b) It will return syntax error, because "while" is a loop statement withot
following colon and anything.
but at a first glance, "while" reads as "if" as in english.
For comparison, what would you expect this to return? (Without actually
> trying
> it, thank you.)
>
> [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5]
>
>
I'd say it will return: [1, 2, 3, 4, 5]
How about these?
>
> [x + y for x in (0, 1, 2, 999, 3, 4) while x < 5 for y in (100, 200)]
>
> [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]
>
No idea... cognitive dissonans ;)
By answering I did not test it and did not look into others answers,
serious.
More information about the Python-list
mailing list