File Sorting in Python

后端 未结 3 749
-上瘾入骨i
-上瘾入骨i 2021-01-29 07:57

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-29 08:36

    f2.writelines(sorted(f1, key=lambda line:int(line.split()[0])))
    

    where f2 is your output file and f1 is your input file.

提交回复
热议问题