Answer to Question #137458 in Python for santosh kasyap

Question #137458
A square n×n matrix of integers can be written in Python as a list with n elements, where each element is in turn a list of n integers, representing a row of the matrix. For instance, the matrix

1 2 3
4 5 6
7 8 9
would be represented as [[1,2,3], [4,5,6], [7,8,9]].

Write a function leftrotate(m) that takes a list representation m of a square matrix as input, and returns the matrix obtained by rotating the original matrix counterclockwize by 90 degrees. For instance, if we rotate the matrix above, we get

3 6 9
2 5 8
1 4 7
Your function should not modify the argument m provided to the function rotate().

Here are some examples of how your function should work.


>>> leftrotate([[1,2],[3,4]])
[[2, 4], [1, 3]]

>>> leftrotate([[1,2,3],[4,5,6],[7,8,9]])
[[3, 6, 9], [2, 5, 8], [1, 4, 7]]

>>> leftrotate([[1,1,1],[2,2,2],[3,3,3]])
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
1
Expert's answer
2020-10-08T05:19:53-0400
Dear santosh kasyap, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS