I am trying to replace values in a 2 dimensional array by accessing values in another array. Last line of my array is repeated even at places where I did not replace it.
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
AA = [[0] * (len(A)+2)] * (len(A)+2)
print(AA)
for r in range(len(A)):
for c in range(len(A[r])):
AA[r+1][c+1] = A[r][c]
print(AA[r+1][c+1], " ")
print(AA)
I expect an output like:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 4, 5, 6, 0], [0, 7, 8, 9, 0], [0, 0, 0, 0, 0]]
But actual output is:
[[0, 7, 8, 9, 0], [0, 7, 8, 9, 0], [0, 7, 8, 9, 0], [0, 7, 8, 9, 0], [0, 7, 8, 9, 0]]