[python]对字典进行排序
2013-05-22 11:09
447 查看
myDict ={"url12.html":12
,"url1112.html":212
,"url346.html":1333
,"url222.html":12
...}
期望按照值的排序进行输出,值有可能一样;
原先以为可以使用外部数组排序后比对输出的,因为值可能重复才发觉不成;
询问 xyb,dreamingk 才知道,原来有内置函式支持的!
"""sorted( iterable[, cmp[, key[, reverse]]])
Return a new sorted list from the items in iterable. Theoptional
arguments cmp, key, and reverse have the same meaning as those forthe
list.sort() method. New in version 2.4.
"""
从2.4 开始数组的排序可以指定键位置!
所以:
for k, v in sorted(myDict.items(), key=lambda x: x[1],reverse=True):
print k,v
就可以获得从大到小的排序字典输出了
来自:http://hi.baidu.com/sleepymole/blog/item/480a1c466400d10b6b63e587.html
,"url1112.html":212
,"url346.html":1333
,"url222.html":12
...}
期望按照值的排序进行输出,值有可能一样;
原先以为可以使用外部数组排序后比对输出的,因为值可能重复才发觉不成;
询问 xyb,dreamingk 才知道,原来有内置函式支持的!
"""sorted( iterable[, cmp[, key[, reverse]]])
Return a new sorted list from the items in iterable. Theoptional
arguments cmp, key, and reverse have the same meaning as those forthe
list.sort() method. New in version 2.4.
"""
从2.4 开始数组的排序可以指定键位置!
所以:
for k, v in sorted(myDict.items(), key=lambda x: x[1],reverse=True):
print k,v
就可以获得从大到小的排序字典输出了
来自:http://hi.baidu.com/sleepymole/blog/item/480a1c466400d10b6b63e587.html
相关文章推荐
- python字典按照value进行排序
- python 按照字典的值进行排序
- <26>python学习笔记——根据字典中的值的大小进行排序
- python高效编程技巧4(如何根据字典中值的大小,对字典的项进行排序)
- python【4】根据字典中值的大小,对字典的键进行排序
- python - 字典按key或者value进行排序(sorted)
- Python利用公共键如何对字典列表进行排序详解
- 005_004 Python 统计值 并按照次数排序 可以通过字典的值对key进行排序
- 对python中的字典进行排序
- python 对字典进行排序
- python_对字典进行排序
- python3使用operator.itemgetter对字典进行排序
- 【Python基础】之对字典进行排序操作(sort by the values of dict)
- python对列表中的字典进行排序
- Python实现字典按照value进行排序的方法分析
- Python sorted 函数,对字典按值进行排序
- python对字典进行排序实例
- Python基础——使字典按照 items 的大小进行排序
- python 对字典按照value进行排序
- python对字典进行排序实例