0

I will miss something. When I want change just "one" value in the nested dictionnary, with tuple keys, all the values with the similary second "key" change, no regards of the first key.

Here the code :

grid = {}
for i in range(3):
    for j in range(3):
        grid[i,j]=''
        
big_grid = {}
for i in range(3):
    for j in range(3):
        big_grid[i,j] = grid

big_grid[2,1][0,0] = "X"

Thanks for the answer.

  • It happens because after second nested loop execution `big_grid` will have 3*3 references to same `grid` dictionary. If you want to *(you want to, trust me)* add copy of dictionary you can use `big_grid[i,j] = {**grid}` or any other way to make copy. Related: [How to copy a dictionary and only edit the copy](https://stackoverflow.com/q/2465921/10824407). – Olvin Roght Jan 23 '22 at 18:12
  • Nice. It works. And its logic. Thank you for your answer Olvin. ^^ – Jérôme Philippe Jan 23 '22 at 18:16

0 Answers0