Python字典排序
来源:互联网 发布:阿里云 dnspod 编辑:程序博客网 时间:2024/06/03 17:49
# -*- coding:UTF-8 -*-def dict_sort(): # 按照value的值从大到小的顺序进行排序 dic = {'a': 31, 'bc': 5, 'c': 3, 'asd': 4, 'aa': 74, 'd': 0} dict = sorted(dic.items(), key=lambda d: d[1], reverse=True) # 默认是从小到大 print 'dict=', dict # 按照key的字母顺序排序 dictt = sorted(dic.items(), key=lambda d: d[0]) print 'dictt=', dicttif __name__ == '__main__': dict_sort()
Output:
dict= [('aa', 74), ('a', 31), ('bc', 5), ('asd', 4), ('c', 3), ('d', 0)]dictt= [('a', 31), ('aa', 74), ('asd', 4), ('bc', 5), ('c', 3), ('d', 0)]
0 0
- python字典排序
- python字典排序
- Python字典排序OrderedDict
- python字典排序
- python 字典排序
- python 字典排序
- python字典排序
- Python字典、列表排序
- python字典排序
- [转]python字典排序
- Python 字典排序
- python 字典排序
- python 字典排序
- python 字典排序
- python 字典排序<转>
- Python 字典排序
- Python 字典排序
- Python 字典排序
- 找回自己
- 城市的三级列表
- word2013中公式居中编号右对齐
- Object-Oriented Analysis and Design Using UML 翻译与学习 (六)
- 时钟类
- Python字典排序
- 五月一战
- Python编码
- 如何在Anaconda下安装MySQLdb,操作系统为Centos Linux, Python 2.7
- 技术面面试总结1
- sparksql udf自定义函数中参数过多问题的解决
- Android API 19以上版本自带的下拉刷新控件SwipeRefreshLayout的使用
- codevs 1006 等差数列 题解报告
- websphere8.5+LDAP+ear war包发布成功,能访问到登录页面,输入用户名密码登录不了