john316
(John M)
1
I can copy a list without reference
a = [3,4,5]
b = a.copy()
b[0] = -1
print(a)
print(b)
>>[3, 4, 5]
>>[-1, 4, 5]
but why can’t I do the same for a list of list? What should I do?
a = [[1,1],[1,1]]
b = a.copy()
b[0][0] = -1
print(a)
print(b)
>>[[-1, 1], [1, 1]]
>>[[-1, 1], [1, 1]]
d_n
(DL Neil)
2
The terms in question are: “shallow-copy” and “deep-copy”.
Web.Refs: