I wanted to make a copy of a list (literally a separated clone that has nothing sharing with the original). I used copy.copy() and created 2 separated lists, but why does the elements of each copy still seem to share?
It's hard to explain, please check out the following output.
>>> a = [[0,1], [2,3]]
>>> import copy
>>> b = copy.copy(a)
>>> temp = b.pop()
>>> temp
[2, 3]
>>> a
[[0, 1], [2, 3]]
>>> b
[[0, 1]]
>>> temp.append(4)
>>> temp
[2, 3, 4]
>>> a
[[0, 1], [2, 3, 4]]
>>> b
[[0, 1]]
As you see, temp is popped from b, yet when I changed temp (aka append new stuff) then the data in a also changed.
My question is: Is this an expecting behavior of deepcopy? How can I make a totally separate copy of a list then?
P/S: As the above example, I guess I can do
temp = copy.copy(b.pop())
but is this a proper way? Is there any other way to do what I want?
P/S 2: This also happens when I use b = a[:]
Thanks!