Apr-07-2021, 05:14 PM
First,
You don't have anything named
I've made some other code to show how this can affect you and one way to avoid it.
list
and iter
are names of classes in python. You shouldn't use them as variable names or you hide the ability to use the class namespaces.You don't have anything named
oldmatrix
in your code, but I can guess what you've done is assumed that assigning a list copies the data rather than just a reference to it. (Please put your code in "python" tags so that the indentation is preserved).I've made some other code to show how this can affect you and one way to avoid it.
baselist = [0, 0, 0, 0] working_list = baselist # copies the object, not the elements inside working_list[2] = "XX" print(f"{working_list=}") print(f"{baselist=}") print() # Note "baselist" has changed without explicitly doing so because it is the same object # as working_list. baselist = [0, 0, 0, 0] working_list = baselist.copy() # This is a copy and the two objects are different working_list[2] = "XX" # doesn't change baselist now. print(f"{working_list=}") print(f"{baselist=}")
Output:working_list=[0, 0, 'XX', 0]
baselist=[0, 0, 'XX', 0]
working_list=[0, 0, 'XX', 0]
baselist=[0, 0, 0, 0]