0
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?

1 Answers1

0

The reference to [False] * len(image [0]) is repeated len(image) times, so modifying the first element of visited affects the second (and third).

deepyaman
  • 538
  • 5
  • 16