按.
分隔的第一个int
值排序为排序key
:
sorted(lst, key=lambda x: int(x.split('.')[0]))
例:
In [20]: lst = ["1. Banana", "2. Pear", "11. Apple", "5. Grapes", "4. Orange"] In [21]: sorted(lst, key=lambda x: int(x.split('.')[0])) Out[21]: ['1. Banana', '2. Pear', '4. Orange', '5. Grapes', '11. Apple']