def rotate_matrix(grid):
return list(map(list, zip(*reversed(grid))))
def print_matrix(grid):
for row in grid:
print(row)
print('----')
grid = [['1', '2'],
['.', '0']]
# check original matrix
print_matrix(grid)
# reverse the outer list
print_matrix(list(reversed(grid)))
# zip the reversed list
print_matrix(rotate_matrix(grid))
Ref
https://stackoverflow.com/questions/53242961/rotating-a-list-of-lists
'CodeSnippet' 카테고리의 다른 글
문자열 분리 (0) | 2022.04.25 |
---|---|
시뮬레이션 - 방향설정 (0) | 2022.04.21 |
댓글