python

超轻量级php框架startmvc

Python有序字典简单实现方法示例

更新时间:2020-05-08 06:42:01 作者:startmvc
本文实例讲述了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 有序字典