I want to sort my tab-delimited data file containing 15 columns according to column[0], i.e. my input file (I illustrate only column 0)
Input file and desired Output file
contig1               contig1
contig102             contig1
contig405             contig2
contig1               contig17
contig2               contig102
contig1005            contig405
contig17              contig1005
The script below sorts, but since 1 < 2, it gives me all contigs having 1 then passes to 2, also since 0 < 1, is gives me 102 before 2, how to improve it?
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
 
    