Problem scenario
You have a list in Python that you copy into another variable. You change the original list and the copied version changes. Why does the copied version get copied and what can you do to overcome this?
Solution
There is something called a "deep" copy and a "shallow" copy. This program will illustrate both the problem and the solution:
list_a = [3, 6, 7]
list_b = list_a
list_c = list_a[:]
list_a.append(4)
print(list_b)
print("list_b, a shallow copy, is above; list_a is below")
print(list_a)
print("a different copy of list_a is below")
print(list_c)
For more information, read the following links: StackOverflow.com and geeksforgeeks.com.