Python 字典排序
2014-09-30 11:37
106 查看
思路是把字典转为列表后再排序
输出结果:
--End--
d={'z':1,'y':2,'x':3} # 字典 s=d.items() # [('y', 2), ('x', 3), ('z', 1)] 列表 s.sort() # [('x', 3), ('y', 2), ('z', 1)] 排序列表 # 或者连起来写(sort是原位操作,sorted是获得列表的副本) # ss=sorted(d.items()) for k,v in s: # 排序后的输出 print k,v
输出结果:
x 3 y 2 z 1
--End--
相关文章推荐
- Python中最快的字典排序方法
- python天天进步(4)--字典排序
- 传说中最快的python字典排序方法
- python的排序函数sort,sorted在列表排序和字典排序中的应用详解和举例
- Python: Trie树实现字典排序
- Python中 字典排序、列表排序
- [转]python字典排序
- Python中 字典排序、列表排序
- python 字典排序
- python天天进步(3)--字典排序
- Python中 字典排序、列表排序
- python 字典排序
- python学习:读写文件和字典排序
- python 字典排序
- python字典排序
- python字典排序
- Python字典排序及简单性能测试
- python 字典排序
- Python字典排序的简单实现
- [转]python字典排序