常州淄博网站优化,软件库合集软件资料2024,中关村网站建设的公司,单页网站怎么做竞价python list字符按数字大小排序在把list写到csv过程中#xff0c;遇到一个list的排序问题#xff0c;list中存放的是数字字符#xff0c;需要按数字大小来排序测试源码testList [1, 5, 2, 10, 50, 21, 31, 3, 7]print(testList{}.format(testList))normalSortList testLis…python list字符按数字大小排序在把list写到csv过程中遇到一个list的排序问题list中存放的是数字字符需要按数字大小来排序测试源码testList [1, 5, 2, 10, 50, 21, 31, 3, 7]print(testList{}.format(testList))normalSortList testList[:]normalSortList.sort()print(after sort(): {}.format(normalSortList))intSortList testList[:]intSortList.sort(key int)print(after sort(keyint): {}.format(intSortList))运行python3 ./test.pytestList[‘1’, ‘5’, ‘2’, ‘10’, ‘50’, ‘21’, ‘31’, ‘3’, ‘7’]after sort(): [‘1’, ‘10’, ‘2’, ‘21’, ‘3’, ‘31’, ‘5’, ‘50’, ‘7’] #会发现这里2在10之后显然不是自己需要的after sort(keyint): [‘1’, ‘2’, ‘3’, ‘5’, ‘7’, ‘10’, ‘21’, ‘31’, ‘50’] #使用sort(keyint)来排序结果就对了作者帅得不敢出门