image=[[1,1,1],[1,1,0],[1,0,1]]
visited = [[False] * len(image[0])] * len(image)
visited[0][0] = True
print((visited[1][0]))
Shouldn't the above python code print False? Why is the entire column being assigned as True?
image=[[1,1,1],[1,1,0],[1,0,1]]
visited = [[False] * len(image[0])] * len(image)
visited[0][0] = True
print((visited[1][0]))
Shouldn't the above python code print False? Why is the entire column being assigned as True?
The reference to [False] * len(image [0]) is repeated len(image) times, so modifying the first element of visited affects the second (and third).