I've tried to make some code for a game in python 3.6.3 and when I try to change a value in a 2d list/array (in a list inside a list), it changes the values of that index in all the lists. Does anybody know why that's the case?
I've abstracted the problem to the exact part of the code that's going wrong. I've tried using different numbers and formats but the problem remains. Debugging tools don't help either.
#Strange error
list_1 = [0,0]
list_2 = [list_1, list_1, list_1]
list_2[0][1] = 1
print(list_2)
#Working normally
list_3 = [[0,0],[0,0],[0,0]]
list_3[0][1] = 1
print(list_3)
The actual result should be that both lists have the same output of [0, 1],[0, 0], [0, 0]. However the first list returns [0, 1],[0, 1],[0, 1] whereas the second list works normally with [0, 1],[0, 0], [0, 0] returned, even though both lists should return the exact same output.