The program gives the desired output but there is a side effect.The argument should not be modified but the function modifies it.
I have already tried making a copy of the argument by taking a full slice of the argument list.
def rotate(m):
A = m[::]
for i in range(len(A)):
for j in range(i + 1, len(A)):
A[i][j], A[j][i] = A[j][i], A[i][j]
for i in range(len(A)):
A[i] = A[i][::-1]
print(A)
rotate([[1,2,3],[4,5,6],[7,8,9]])
The expected output is:
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
The output is as expected. The code should not modify the argument but it does.