So i was trying to recreate game of life in python using a 2 dimensional array, but i stumbled into a really weird bug. To make the array i made this function:
def MakeGrid(height):
gridY = []
grid = []
for i in range(height):
gridY.append(False)
for i in range(height):
grid.append(gridY)
return(grid)
But there is a really weird bug where if i try to change a False into a True in only 1 spot, it changes everywhere diagonally. Here's an example:
grid = MakeGrid(2) # grid is now [[False,False], [False,False]]
grid[0][0] = True #grid should be [[True, False], [False, False]], but it's actually [[True, False], [True, False]]
I really don't know what causes this but it's really annoying me and i would really love some help.