Sander Sweers wrote:
2009/3/7 Alan Gauld <[email protected]>:
mycopy = original[:]
Returns a slice of the original list. In this case it so happens
the slice is the full list.
mycopy = list(original)
Use the list type constructor to make a list out of its argument.
It just so happens the argument in this case is a list.
Both not give the desired result with nested lists and this is why you have..
What is the desired result?
Sometimes I might want to copy a list, but keep the referenced items the
same. In which case I'd use the slice copying or list constructor copying.
Any way, there is one unmentioned way to copy a list:
listcopy = [x for x in mylist]
though it might be slower and more verbose.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor