Write a function rotate(m) that takes a list representation m of a square matrix as input, and returns the matrix obtained by rotating the original matrix clockwize by 90 degrees. For instance, if we rotate the matrix above, we get
the matrix is n*n
>>> rotate([[1,2,3],[4,5,6],[7,8,9]])
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
>>> rotate([[1,1,1],[2,2,2],[3,3,3]])
[[3, 2, 1], [3, 2, 1], [3, 2, 1]]
What I have tried:
def rotate(m):
l1=m[::]
n=len(m)-1
count=n
for i in range(n+1):
for j in range(n+1):
l1[j][count]=l1[i][j]
count-=1
return l1