我要排序含有根据列15列我的制表符分隔的数据文件排序名[0],即我的输入文件(I仅示出了柱0)包含数字
输入文件和期望的输出文件
contig1 contig1
contig102 contig1
contig405 contig2
contig1 contig17
contig2 contig102
contig1005 contig405
contig17 contig1005
以下各种脚本,但由于1 < 2,它给了我所有的重叠群为1,然后传给2,也因为0 < 1时,给了我102 2之前,如何提高呢?
f1 = open('file.txt','r')
a=sorted(f1.readlines(), key=lambda l: l.split()[0]))
r=open('file.txt','w')
r.writelines(a)
f1.close
假设他们都开始重叠群,你可以只排序INT(S [6:]) – Antimony
如果这是一个可能性,理想你应该在号码前加上无意义的'0'数字。另一种可能性,如果你总是有字符串+数字顺序,将是分割,按字符串排序,然后按数字排序,但这有点棘手......如果字符串总是相同的,锑的建议绝对是好的。 –
可能的重复[Python是否有内置的字符串自然排序函数?](http://stackoverflow.com/questions/4836710/does-python-have-a-built-in-function-for-string-natural -sort) – RedX