【发布时间】:2020-06-27 04:59:09
【问题描述】:
我尝试对实际上是整数的字符串列表进行排序,但我没有得到正确的排序值。如何按照字符串的整数值排序?
a = ['10', '1', '3', '2', '5', '4']
print(sorted(a))
输出:
['1', '10', '2', '3', '4', '5']
想要的输出:
['1', '2', '3', '4', '5', '10']
【问题讨论】:
-
a.sort(key=int)可能与How to sort python list of strings of numbers重复
标签: python python-3.x string sorting