Why are the two outputs different:
The only difference in the 2 approaches is the way the matrix has been initialized. I expect to get the same output in both the scenarios but the output seems to be different?
Is there something I am missing?
x = 4
table = [[0]*(x)]*x
for i in range(x):
table[i][i] = 1
print(table)
table: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
x = 4
table = [[0]*x for i in range(x)]
for i in range(x):
table[i][i] = 1
print(table)
table: [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]