Python list 按元素属性排序, key 的用法

>>> a.append(('a',1))
>>> a.append(('b',20))

>>>a.append(('c',-200))

>>> a.sort(key=lambda d:d[1],reverse=True)
>>> a
[('b', 20), ('a', 1), ('c', -200)]

原文地址:https://www.cnblogs.com/finallyliuyu/p/1791244.html