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 ouputs:
three
three
three
Is this really an expected behavior? Could you explain why this is not:
one
two
three