>>> m=[[-1]*2]*2
>>> n=[[-1,-1],[-1,-1]]
>>> m==n
True
>>> for i in range(2):
... m[i][i]=10
...
>>> m
[[10, 10], [10, 10]]
>>> for i in range(2):
... n[i][i]=10
...
>>> n
[[10, -1], [-1, 10]]
In the code block above, the assignment to the elements of n takes place as expected, but the assignment to elements of m is incorrect although both m and n before the assignment are equal, and the assignment takes place in the same manner. Can someone please clarify? Is this a bug in the usage of the * operator for the creation of the original list? This is Python 3.10.0.