本文实例讲述了Python有序字典简单实现方法。分享给大家供大家参考,具体如下:代码:#-*
本文实例讲述了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 有序字典