+ 3
list in list
I am expecting only grid[2][2] is altered,but why is every 3rd value in the sublists altered? Is there any way to solve it? https://code.sololearn.com/cD3HgLUkQ78g/?ref=app
1 Answer
+ 7
By plainly multiplying lists, what you are doing is creating multiple objects that point to the same address. Therefore a change to one is a change to all.
What you can do is:
[[[] for I in range(3)] for J in range(3)]