本文实例讲述了Python有序字典简单实现方法。分享给大家供大家参考,具体如下:
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# -*- 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程序设计有所帮助。
原文链接:http://blog.csdn.net/xiecj_2006/article/details/42320279