Deep vs Shallow Copy

11_deep_copy

Deep vs Shallow Copy

In [0]:
from copy import deepcopy
In [0]:
a = []
b = []
c = []

some_list = [a, b, c]
some_other_list = some_list  # Shallow Copy
a.append(42)
print(some_other_list)
[[42], [], []]
In [0]:
a = []
b = []
c = []

some_list = [a, b, c]
some_other_list = deepcopy(some_list)  # Deep Copy
a.append(42)
print(some_other_list)
[[], [], []]
In [0]: