发布时间:2019-07-26 09:39:00编辑:auto阅读(2297)
python 2 中支持类似 c++ 中 cmp 的写法
python 3 放弃了这一用法
官方说明:https://docs.python.org/3/howto/sorting.html#sortinghowto
多元素比较时可以写成:
a = [[1,2],[2,1],[1,1],[2,2]]
print(a)
a.sort(key=lambda x:(-x[0],x[1]))
print(a) 第一元素逆序,第二元素正序
上一篇: python3-字典的增删改查
下一篇: python 获取句柄,关闭进程
51164
50572
41193
38022
32486
29391
28251
23107
23070
21393
1443°
2158°
1789°
1711°
2017°
1785°
2462°
4143°
4010°
2862°