with open("x.txt", "r") as infile:
# Read line by line and split by space already
x = [[k for k in j.split()] for j in [i.strip("\n") for i in infile if i != "\n"]]
cols, rows = max([len(i) for i in x]), len(x) # Get dimensions
output = []
# Transpose, swap rows and columns
for i in range(cols):
for j in range(rows):
try:
output.append(x[j][i])
except IndexError:
pass
# Construct the desired output string
retstr = ""
for i in output:
retstr += i+" "
print(retstr)
你可以阅读内容,找出尺寸,然后转置:
相关问题 更多 >
编程相关推荐