I've been experiencing a quite strange error while using python.
I have a variable named graph
, which is a list of lists and I'm modifying and a variable copy
which
is supposed to "remember" the original value of graph
.
However, when I apply the remove() method to graph
the value of copy also changes!
Here is a reproducible example:
graph = [[1,2],[2,3],[3,1]]
copy = graph
print("graph =" + str(graph))
print("copy =" + str(copy))
graph[0].remove(2)
print("graph =" + str(graph))
print("copy =" + str(copy))
Does anyone know how to deal with this issue?