0

using the walrus operator gives confusing output,

i = 0
{i := i + j for j in [1, 2, 3]}

gives the expected,

{1, 3, 6}

with

print(i)
6

but when we re-run the same expression again,

{i := i + j for j in [1, 2, 3]}

gives,

{9, 12, 7}

should it not have been,

{7, 9, 12}

the value of i is correct, that is 12 running it again and again,

{i := i + j for j in [1, 2, 3]}

gives,

{18, 13, 15}
{24, 19, 21}
{25, 27, 30}
{33, 36, 31}
apostofes
  • 2,233
  • 2
  • 12
  • 29

0 Answers0