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])]
>>>
{'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])]
>>>
相关文章推荐
- python中List的sort方法(或者sorted内建函数)的用法
- python中对字典排序的sorted函数用法
- Python: sort,sorted,OrderedDict的用法
- python中List的sort方法(或者sorted内建函数)的用法
- python 中 sorted() 和 list.sort() 的用法
- python笔记(2)排序函数sorted的用法
- 【转】python中List的sort方法(或者sorted内建函数)的用法
- python3手册 中的sorted 用法详解
- python sort、sorted 高级用法
- Python中sorted()方法的用法
- Python3.x与Python2.x关于sorted函数用法比较
- python 小程序,按照姓名或成绩排序(sorted用法)
- python中List的sort方法(或者sorted内建函数)的用法
- python排序之sort,sorted用法
- python sorted()函数用法
- Python中sorted()方法的用法
- python内置函数sorted排序用法
- Python: sort,sorted,OrderedDict的用法
- Python中sorted()方法的用法
- python 中 sorted() 和 list.sort() 的用法