while True:
try:
m,n = input().split()
m = int(m)
n = int(n)
matrix = []
for i in range(m):
matrix.append(input().split())
for i in range(n):
for j in range(m):
print(matrix[j][i],end = " ")
print()
except:
break
from sys import stdin
for i in tuple(zip(*((int(j) for j in i.split()) for i in tuple(stdin)[1:]))):
print(*i)
忘記要重複輸入了~
from sys import stdin try: while True: n=int(next(stdin).split()[0])
array=[next(stdin) for i in range(n)] for i in tuple(zip(*((int(j) for j in i.split()) for i in array))):print(*i) except StopIteration:pass
可以更短
from sys import stdin
try:
while True:
for i in tuple(zip(*((int(j) for j in next(stdin).split()) for i in range(int(next(stdin).split()[0]))))):print(*i)
except StopIteration:pass