【发布时间】:2017-01-03 19:24:39
【问题描述】:
对 zip 很着迷,我突然想到可以将它用于矩阵转置。
这是python代码:
import sys
n = raw_input("enter the number of rows of the matrix:")
x = []
for i in range(int(n)):
y = map(int,raw_input().split())
x.append(y)
mat = zip(*x)
print ""
for i in mat:
for j in i:
sys.stdout.write(str(j))
sys.stdout.write(" ")
sys.stdout.write("\n")
但我对我的代码看起来不太满意。我该如何改进它?
谢谢!
编辑:
Input:
1 2
3 4
5 6
7 8
Output:
1 3 5 7
2 4 6 8
【问题讨论】: