Consider this short code snippet:
class X:
pass
xs = []
for s in ("one", "two", "three"):
x = X()
x.f = lambda: print(s)
xs.append(x)
for x in xs:
x.f()
It outputs:
three
three
three
I thought the result should be like this instead:
one
two
three
Why is that not the actual result?