1 matrix=[
2 [1,2,3,4,4,3,2,1],
3 [5,6,7,8,8,7,6,5],
4 [9,10,11,12,12,11,10,9],
5 ]
6
#
#one
7 transposed=[]
8
for i
in range(4):
9 transposed.append([row[i]
for row
in matrix])
10
print(transposed)
11
#
[Finished in 0.9s]
12
13
#
#two
14
#
transposed2=[]
15
#
for i in range(4):
16
#
transposed2_row=[]
17
#
for row in matrix:
18
#
transposed2_row.append(row[i])
19
#
transposed2.append(transposed2_row)
20
#
print(transposed2)
21
#
[Finished in 0.3s]
22
23
#
three ---#%the most fast method%#
24
#
print([[row[i] for row in matrix] for i in range(4)])
25
#
[Finished in 0.2s]
26
27
#
four
28
#
print(list(zip(*matrix)))
29
#
[Finished in 0.3s]