每天一点python -- python字典排序
来源:互联网 发布:吉林大学网络课程中心 编辑:程序博客网 时间:2024/06/09 14:30
参考:http://www.cnblogs.com/kaituorensheng/archive/2012/08/07/2627386.html
http://www.cnblogs.com/BeginMan/p/3193081.html
dict={'A':1,"C":2,“B”:4,“E”:3}
在python 的字典是一个无序的存储结构,每个元素是key-value对。
对字典按值排序:
print sorted(dict.iteritems(),key=lambda dict:dict[1],reverse=True)
对字典按键排序:
print sorted(dict.iteritems(),key=lambda dict:dict[0],reverse=False)
函数原型:sorted(dic,value,reverse)
解释:
1.iteritems() (元组的形式)
功能:iteritems()以迭代器对象返回字典键值对
2.reverse()
reverse:注明升序还是降序,True--降序,False--升序(默认)
0 0
- 每天一点python -- python字典排序
- 每天一点python--assert断言
- 每天一点python——python数据类型
- 【Python】Python对字典排序
- python字典排序
- python字典排序
- Python字典排序OrderedDict
- python字典排序
- python 字典排序
- python 字典排序
- python字典排序
- Python字典、列表排序
- python字典排序
- [转]python字典排序
- Python 字典排序
- python 字典排序
- python 字典排序
- python 字典排序
- 自定义imageView使用遮罩实现
- 更正:关于UFT12.51破解事宜
- git常用指令
- 微信JS分享实战代码
- Putty Command-Line Parameter
- 每天一点python -- python字典排序
- 科普dip,dp,sp,dpi,ppi,px,Density
- Ubuntu下编译Openpilot
- PowerShell 之 DNS Server (1)
- 使用PCH及巧妙使用NSLog
- 关于OpenCV的那些事——相机姿态更新
- 点击文字弹出一个DIV层窗口代码
- 面向对象的编程——只想new一个更好的对象
- 解析URL参数 获取参数值(二维码URL解析)