New to python and having trouble with populating a list.
mat = [[0]*3]*4
for i in range(4):
for j in range(3):
mat[i][j] = (i,j)
print(mat)
The piece of code above prints out:
[[(3, 0), (3, 1), (3, 2)],
[(3, 0), (3, 1), (3, 2)],
[(3, 0), (3, 1), (3, 2)],
[(3, 0), (3, 1), (3, 2)]]
When I thought it should print out something like:
[[(0, 0), (0, 1), (0, 2)],
[(1, 0), (1, 1), (1, 2)],
[(2, 0), (2, 1), (2, 2)],
[(3, 0), (3, 1), (3, 2)]]
I realize this might be a simple question, but what am I doing wrong? Everywhere online tells me to populate a list this way as well.
Thanks in advance!