我正在尝试对包含数字的字符串列表进行排序
a = ["1099.0","9049.0"] a.sort() a ['1099.0', '9049.0'] b = ["949.0","1099.0"] b.sort() b ['1099.0', '949.0'] a ['1099.0', '9049.0']
但是列表b是排序而不是列表a
b
a
您要基于float值(而不是字符串值)进行排序,因此请尝试:
float
>>> b = ["949.0","1099.0"] >>> b.sort(key=float) >>> b ['949.0', '1099.0']