In python, I am trying to assign an integer to a specific location inside a list. However, the value gets assigned to all several locations. Obviously, python is assigning value by reference and not value, but why?
matrix = [[[0,0]] * (5) for _ in range(2)]
matrix[1][3][0] = 42
Initial:
[
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
]
Expected (after assignment):
[
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 0], [42, 0], [0, 0]]
]
Actual (after assignment):
[
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
[[42, 0], [42, 0], [42, 0], [42, 0], [42, 0]]
]