这篇文章主要介绍了python有序字典简单实现方法,涉及python使用ordereddict方法进行字典排序的相关操作技巧,需要的朋友可以参考下
本文实例讲述了python有序字典简单实现方法。分享给大家供大家参考,具体如下:
代码:
# -*- coding: utf-8 -*-
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实现有序字典方法示例的详细内容。