gpt4 book ai didi

python - 在python中转置一个数字表

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:37 25 4
gpt4 key购买 nike

我需要用python写下面的数据,

student score
Bill 43
Suzy 54
Sally 41

但我也得把它翻过来看起来像

student Bill Suzy Sally
score 43 54 41

我已经写好了,

ofile = open('grades','r')
Tfile = open('Tgrades','u')
date = []
while 1:
a = ofile.readline()
if a=='':
break
data.append(a.split())

最佳答案

with open ('yourfile') as fin:
lines = (line.split() for line in fin)
for row in zip(*lines):
print ' '.join(row)

关于python - 在python中转置一个数字表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com