If I create a two dimensional matrix as follows:
n = 5
m = 5
l = [[0] * n] * m
l[0][0] = 1
print(l)
will output:
[[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0]]
Why? why are all the sub-lists first elements being set to 1??