怎样用Python将下面的数据读取到入数组中.并且对倒数后三列的值进行升序排序,第二三四五列数据可以不要 10
348,2,2,0,4,199,194,196349,2,2,0,4,97,199,196350,2,2,0,4,189,198,195351,2,2,0,4,196,1...
348,2,2,0,4,199,194,196
349,2,2,0,4,97,199,196
350,2,2,0,4,189,198,195
351,2,2,0,4,196,194,198
352,2,2,0,4,200,84,195
353,2,2,0,4,198,200,195
354,2,2,0,4,201,192,196
355,2,2,0,4,198,201,196
356,2,2,0,4,184,201,189
357,2,2,0,4,201,184,192
(TXT文件,求解) 展开
349,2,2,0,4,97,199,196
350,2,2,0,4,189,198,195
351,2,2,0,4,196,194,198
352,2,2,0,4,200,84,195
353,2,2,0,4,198,200,195
354,2,2,0,4,201,192,196
355,2,2,0,4,198,201,196
356,2,2,0,4,184,201,189
357,2,2,0,4,201,184,192
(TXT文件,求解) 展开
2个回答
展开全部
with open('a.txt') as f:
s=f.read()
L=[i.strip() for i in s.strip().split('\n')]
L2=[[int(i)for i in j.split(',')] for j in L]
L2.sort(key=lambda s:s[-1]) #按最后一列排序
L3=[i[-3:] for i in L2] #去除前几列,只保留后3列
with open('b.txt','w') as wf:
wf.write('\n'.join([','.join(i) for i in L3]))
追问
最后一句报错啊
TypeError: sequence item 0: expected string, int found
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询