本文摘自php中文网,作者黄舟,侵删。
这篇文章主要介绍了Python有序字典简单实现方法,涉及Python使用OrderedDict方法进行字典排序的相关操作技巧,需要的朋友可以参考下本文实例讲述了Python有序字典简单实现方法。分享给大家供大家参考,具体如下:
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import collections
print 'Regular dictionary:'
d = {}
d[ 'a' ] = 'A'
d[ 'b' ] = 'B'
d[ 'c' ] = 'C'
for k, v in d.items():
print k, v
print '\nOrderedDict:'
d = collections.OrderedDict()
d[ 'a' ] = 'A'
d[ 'b' ] = 'B'
d[ 'c' ] = 'C'
for k, v in d.items():
print k, v
|
执行结果:
以上就是Python实现有序字典方法示例的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python怎么避免随机元素重复
Python怎么写图形界面gui
Python全栈是什么意思
Python能做什么
Python3.6如何导入excel里面的数据
Python基础学完后再学什么
Python numpy中nonzero()应该如何使用
读懂Python的异常机制
只学Python能找工作吗
Python中如何进行检索和替换(实例解析)
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python实现有序字典方法示例