Basically, this is what the problem is. I have a class with an optional parameter: lst. lst is a nested list. Below is a method that returns another instance of the class that it is inside.
self.lst = [[[1, 2]]] # this is defined in the constructor
s = self.lst
for a in s:
for b in a:
if b[0] != item:
b[0] = 5
return ChangeNumb(lst=s)
What happens after this is VERY weird. Returning ChangeNumb.lst is now [[[5, 2]]], but the class that the method is run in ALSO ChangeNumb.lst == [[[5, 2]]].
So that instead of just returning a new instance of a class with a different parameter, this method changes the self.lst of the class it is inside as well.
I need to make it so that self.lst does not change, while returning a new instance.
PLEASE HELP
EDIT: Although I've encountered a similar problem when writing the class constructor, I was able to resolve it as -> self.lst = lst.copy(); however, s = self.lst.copy() does not work!
list.copyisn't a method that exists. To copy a list, you can just slice it:lst[:].copy.deepcopy()