I would like to sort a file in Python based on numerical values:
My input file looks like this:
66135 - A 65117 - B 63301 - C 63793 - D
Here is a complete code for that.
with open('inputFileName') as fp: lst = map(lambda s:s.rstrip(), fp.readlines()) with open('outputFileName', 'w') as fp: fp.write("\n".join(sorted(lst, key=lambda s:int(s.split()[0]))))