I was investigating this a bit more,
it turns out that I cannot use walrus with tuple also,
so,
print([[(x, y) := (i*2, i*3), x, y] for i in range(1, 5)])
gives,
SyntaxError: cannot use assignment expressions with tuple
but the way I want it to work is, it outputs,
[[(2, 3), 2, 3], [(4, 6), 4, 6], [(6, 9), 6, 9], [(8, 12), 8, 12]]
I assume, when I write,
[[[x] := [i*2], x] for i in range(1, 5)]
then the, [x] := [i*2]
part should do two things,
- return
[i*2]
(that is, whatever comes after the walrus operator)
- set
[x] = [i*2]
and this value of x
would be used in the second entry of the list in my previous post, that is here,
[[x] := [i*2], x]
^