matrix rotation 90 deg anti clockwise in python code example
Example 1: rotate matrix 90 degrees clockwise python
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]
Example 2: rotate matrix 90 degrees clockwise in python
m,n = map(int,input().split())
l = []
for i in range(m):
x = list(map(int,input().split()))
l.append()
for i in range(m):
for j in range(m-1,-1,-1):
print(l[j][i],end=' ')
print(end='\n')