本文摘自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软件收费吗
Python标准库需要导入吗
手机有什么Python编译器
Python爬虫任务接单渠道
Python简单实现控制电脑的方法
浅谈Python中重载isinstance继承关系的问题
Python的for循环怎么理解
Python有什么数据结构
Python整数怎么表示
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python实现有序字典方法示例