Last active
November 22, 2017 04:35
-
-
Save danquixote/3f3213e19b9f748056d7a0096a33e827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
see also: | |
https://gist.github.com/danquixote/64d12eebef39c50f4adf2204d6dbf2ef | |
""" | |
MATRIX = [ | |
[1,2,3], | |
[4,5,6], | |
[7,8,9], | |
] | |
"""matrix out: | |
7,4,1 | |
8,5,2 | |
9,6,3 | |
""" | |
def rotate_square_matrix_90_deg_right(matrix): | |
outer_list = [] | |
matrix = list(reversed(matrix)) | |
for ii in range(0, len(matrix)): | |
lst = [] | |
for row in matrix: | |
lst.append(row[ii]) | |
if len(lst) == len(row): | |
outer_list.append(lst) | |
return outer_list | |
if __name__ == '__main__': | |
print(rotate_square_matrix_90_deg_right(MATRIX)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see the more extensible version at:
https://gist.github.com/danquixote/64d12eebef39c50f4adf2204d6dbf2ef