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
you can try this way
with open('filename','r') as file: # spilt() the line with '-' lis=[line.strip().split('-') for line in file] # sort the lis using the values print sorted(lis,key=lambda x:int(x[0].strip()))