如何按照插入顺序从字典中检索项目? [英] How do you retrieve items from a dictionary in the order that they're inserted?

查看:28
本文介绍了如何按照插入顺序从字典中检索项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以按照插入顺序从 Python 字典中检索项目?

Is it possible to retrieve items from a Python dictionary in the order that they were inserted?

推荐答案

标准 Python dict 默认情况下,如果您使用 CPython 3.6+(或 Python 3.7+ 用于任何其他实现蟒蛇).

The standard Python dict does this by default if you're using CPython 3.6+ (or Python 3.7+ for any other implementation of Python).

在旧版本的 Python 上,您可以使用 collections.OrderedDict.

On older versions of Python you can use collections.OrderedDict.

这篇关于如何按照插入顺序从字典中检索项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆