On 2017-08-10 20:11, Jussi Piitulainen wrote:
MRAB writes:
[snip]
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)]
Thanks for your comments!
There's a subtlety there.
Initially I would've thought that the 'while' would terminate the
iteration of the preceding 'for', but then when I thought about how I
would expand it into multiple lines, I realised that the 'while' would
have to be expanded to "if x < 5: break", not an inner 'while' loop.
Oops! Of course I meant "if not (x < 5): break".
I wonder how such expansions would work in general.
[x + y for x in (0, 1, 2, 999, 3, 4) for y in (100, 200) while x < 5]
[x + y for x in (0, 1, 2, 999, 3, 4) for y in (100, 200) while x < y]
--
https://mail.python.org/mailman/listinfo/python-list