SHARE
TWEET

Untitled

a guest Jun 27th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def rotate_matrix(matrix):
  2.     n = len(matrix)
  3.     res = [[None] * n] * n
  4.  
  5.     for n_row in range(n):
  6.         for n_col in range(n):
  7.             res[n_row][n_col] = matrix[n - n_col -1][n_row]
  8.     return res
  9.      
  10. test = [[1, 2, 3, 4, 5],
  11.         [6, 7, 8, 9, 10],
  12.         [11, 12, 13, 14, 15],
  13.         [16, 17, 18, 19, 20],
  14.         [21, 22, 23, 24, 25]]
  15.  
  16. print(rotate_matrix(test))
  17.  
  18. # [[25, 20, 15, 10, 5],
  19. #  [25, 20, 15, 10, 5],
  20. #  [25, 20, 15, 10, 5],
  21. #  [25, 20, 15, 10, 5],
  22. #  [25, 20, 15, 10, 5]]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top