Question : rotate matrix 90 degrees clockwise python
Answered by : thoughtless-tiger-jgoiwhw6mwmn
#rotate 90 deg clockwise
box=[["a","b"],["c","d"],["e","f"]]
rows = len(box)
cols = len(box[0])
box2 = [[""] * rows for _ in range(cols)]
for x in range(rows): for y in range(cols): box2[y][rows - x - 1] = box[x][y]
Source : | Last Update : Sun, 23 May 21
Question : rotate 90 degrees clockwise counter python
Answered by : successful-squirrel-yy4ky7hg631p
new_matrix = [[m[j][i] for j in range(len(m))] for i in range(len(m[0])-1,-1,-1)]
Source : https://stackoverflow.com/questions/53250821/in-python-how-do-i-rotate-a-matrix-90-degrees-counterclockwise | Last Update : Mon, 24 Aug 20
Question : rotate matrix 90 degrees clockwise in python
Answered by : hanu7674
#The program defines the square matrix 90 degrees clockwise direction.
m,n = map(int,input().split())
#m,n are the number of rows and columns.
#m = int(input('rows'))
l = []
for i in range(m): x = list(map(int,input().split())) #for taking the rows a time and split it append to an empty list l.append()
for i in range(m): for j in range(m-1,-1,-1): print(l[j][i],end=' ') print(end='\n')
Source : | Last Update : Mon, 18 Jan 21