I have created two lists in Python (lst_A
and lst_B
). I checked and those lists are equal. However, they act differently during value assignment, why is that?
I would like to create a list as with procedure B but with 'behaviour' of list A.
lst_B = [[0]*2]*2
lst_A = [[0, 0], [0, 0]]
print(lst_A == lst_B) # returns True
lst_B[0][0] = 1
print(lst_B) # returns [[1, 0], [1, 0]]
lst_A[0][0] = 1
print(lst_A) # returns [[1, 0], [0, 0]]