i need to sort the first column of a table. it looks something like
6000 799
7000 352
8000 345
9000 234
10000 45536
11000 3436
1000 342
2000 123
3000 1235
4000 234
5000 233
i want the first column to be in ascending order, but it is sorting it by only the first digit, not the value of the whole column, i.e.
1000 342
10000 45536
11000 3436
2000 123
But i want
1000 342
2000 123
3000 1235
etc
Currently trying:
SortInputfile=open("InterpBerg1","r")
line=SortInputfile.readlines()
line.sort()
map(SortOutputfile.write, line)
The
sortandsortedfunction support a key argument which allows you to specify the key which should be used to perform the sorting. Since you want a numerical sort order and no alphabetical sort order you need to extract the first column and convert it to an int:A cleaner version of this could would be: