List behaviour

Mike Kent mrmakent at cox.net
Wed May 17 11:18:33 EDT 2006


When you did:
b = a[:]

b was then a copy of a, rather than just a reference to the same a.
But what does a contain?  It contains two sublists -- that is, it
contains references to two sublists.  So b, which is now a copy of a,
contains copies of the two references to the same two sublists.

What you need to do instead is:
b = copy.deepcopy(a)

to get you what you actually want.




More information about the Python-list mailing list