Skip to content

Instantly share code, notes, and snippets.

@danquixote
Last active November 22, 2017 04:35
Show Gist options
  • Save danquixote/3f3213e19b9f748056d7a0096a33e827 to your computer and use it in GitHub Desktop.
Save danquixote/3f3213e19b9f748056d7a0096a33e827 to your computer and use it in GitHub Desktop.
#!/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))
@danquixote
Copy link
Author

Please see the more extensible version at:
https://gist.github.com/danquixote/64d12eebef39c50f4adf2204d6dbf2ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment