PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#define original matrix
org = [[1,2,3], [4,5,6], [7,8,9]]
#define rot function that rotates matrix
# rot(x,y) rotates x, y times, + for CW, - CCW
rot = lambda x,y=1: x if y==0 else rot(list(zip(*x[::-1])),((4+y)%4,y%4)[y>=0]-1)
#define p function for nice matrix printout
p = lambda x: [print(*row) for row in x]
print('Clockwise')
for y in range(4):
print(f"rot(org,{y})")
p(rot(org,y))
print()
print('Anti - clockwise')
for y in range(0,-4,-1):
print(f"rot(org,{y})")
p(rot(org,y))
print()
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run