Weird lambda rebinding/reassignment without me doing it
hat at se-162.se.wtb.tue.nl
Thu Jul 10 16:10:32 CEST 2008
Python doesn't use value semantics for variables but reference semantics:
a = 
b = a
In many languages, you'd now have 2 lists. In Python you still have one list,
and both a and b refer to it.
Now if you modify the data (the list), both variables will change
a.append(2) # in-place modification of the list
print b # will print [1,2]
If you don't want this, you should make a copy somewhere
a = a + 
b = a[:]
It takes a bit of getting used to, but it is very handy in practice.
Read the docs about 'immutable' and 'mutable' types.
(I expected this to be a FAQ, but I couldn't quickly find a matching entry)
More information about the Python-list