您的位置:首页 > 编程语言 > Python开发

python sorted用法

2012-11-13 19:19 232 查看
>>> a
{'a': [1, 3], 'b': [2, 4]}
>>> a.items()
[('a', [1, 3]), ('b', [2, 4])]
>>> sorted(a.items(),key=lambda x:x[1][2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <lambda>
IndexError: list index out of range
>>> sorted(a.items(),key=lambda x:x[1][1])
[('a', [1, 3]), ('b', [2, 4])]
>>> sorted(a.items(),key=lambda x:x[1][1],reverse=True)
[('b', [2, 4]), ('a', [1, 3])]
>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: