这篇文章主要介绍了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免费学习笔记(深入)”;
以上就是Python实现有序字典方法示例的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号