1
我有这样用行的文件:重排列表中的特定行
r1 1 10
r2 10 1 #second bigger than third (10>1)
r3 5 2 # "" "" (5>2)
r4 10 20
而且我想重新排序与所述第二字比第三大的线条,改变[3] possition到[2 ] possition。
所需的输出:
r1 1 10
r2 1 10
r3 2 5
r4 10 20
我已经作出重新排序行代码,但它只是重新排序线路输出,但并不是所有的线路:
with open('test','r') as file, open('reorderedtest','w')as out:
for line in file:
splitLine = line.split("\t")
reorderedlist = [splitLine[0], splitLine[2], splitLine[1] ]
if int(splitLine[1]) > int(splitLine[2]):
str = " "
print str.join(reorderedlist)
而且只打印:
r2 1 10
r3 2 5
任何想法来获得我想要的输出?