好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python实现有序字典方法示例

这篇文章主要介绍了Python有序字典简单实现方法,涉及Python使用OrderedDict方法进行字典排序的相关操作技巧,需要的朋友可以参考下

# -*- 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实现有序字典方法示例的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于Python实现有序字典方法示例的详细内容...

  阅读:40次