I've tried changing a single value in a simple 2d array after initializing it but instead, it changed the column. But the same thing is working if I do it the other way. Why is that?
>>> arr=[[None]*4]*4
>>> arr
[[None, None, None, None],
[None, None, None, None],
[None, None, None, None],
[None, None, None, None]]
# My problem
>>> arr[1][2]=0
>>> arr
[[None, None, 0, None],
[None, None, 0, None],
[None, None, 0, None],
[None, None, 0, None]]
# But it works like this
>>> arr=[[None for _ in range(4)] for _ in range(4)]
>>> arr[1][2]=0
>>> arr
[[None, None, None, None],
[None, None, 0, None],
[None, None, None, None],
[None, None, None, None]]