can someone please explain why this is happening, the problem is when I update the value of the matrix its duplicate matrix (a) also get updated automatically so Is there any way to keep the value of duplicate matrix as what it is?
python3
matrix=[[1,2,3],[4,5,6],[7,8,9]]
a=matrix
for i in range(len(a)):
for j in range(len(a)):
matrix[i][j]=a[j][len(a)-1-i]
print(a)
Output
[[3, 2, 3], [4, 5, 6], [7, 8, 9]]
[[3, 6, 3], [4, 5, 6], [7, 8, 9]]
[[3, 6, 9], [4, 5, 6], [7, 8, 9]]
[[3, 6, 9], [6, 5, 6], [7, 8, 9]]
[[3, 6, 9], [6, 5, 6], [7, 8, 9]]
[[3, 6, 9], [6, 5, 8], [7, 8, 9]]
[[3, 6, 9], [6, 5, 8], [3, 8, 9]]
[[3, 6, 9], [6, 5, 8], [3, 6, 9]]
[[3, 6, 9], [6, 5, 8], [3, 6, 3]]