Proposed new syntax
Skip Montanaro
skip.montanaro at gmail.com
Thu Aug 10 11:04:20 EDT 2017
> What would you expect this syntax to return?
>
> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]
[1, 2, 3]
> 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]
[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)]
[100, 200, 101, 201, 102, 202]
> [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]
[100, 200, 101, 201, 102, 202, 103, 203, 104, 204]
Skip
More information about the Python-list
mailing list