在
key函数中指定参数
sorted。
>>> tuple1=[(1, 3), (3, 2), (2, 1)]>>> output = sorted(tuple1, key=lambda x: x[-1])>>> print output[(2, 1), (3, 2), (1, 3)]
该
sorted函数(以及
list.sort方法)具有一个可选
key参数,用于指定要对列表进行排序的内容。

在
key函数中指定参数
sorted。
>>> tuple1=[(1, 3), (3, 2), (2, 1)]>>> output = sorted(tuple1, key=lambda x: x[-1])>>> print output[(2, 1), (3, 2), (1, 3)]
该
sorted函数(以及
list.sort方法)具有一个可选
key参数,用于指定要对列表进行排序的内容。