简体   繁体   English

Python中的OrderedDict

[英]OrderedDict in Python

I'm learning about OrderedDicts in python but when I create new dictionaries it preserves the order anyway. 我正在学习python中的OrderedDicts,但是当我创建新的词典时,它仍然保留了订单。 I can't seem to find a good example of why you'd ever need to use an OrderedDict. 我似乎无法找到一个很好的例子,说明为什么你需要使用OrderedDict。

For reference, if I do this: 作为参考,如果我这样做:

x = {"one":1,"two":2,"three":3}

print(x)

it will always print out {'one': 1, 'two': 2, 'three': 3} 它将始终打印出{'one':1,'two':2,'three':3}

I'm just looking to understand why we need OrderedDicts. 我只是想了解为什么我们需要OrderedDicts。

I'm learning about OrderedDicts in python but when I create new dictionaries it preserves the order anyway. 我正在学习python中的OrderedDicts,但是当我创建新的词典时,它仍然保留了订单。

This is accidentally the case with python 3.6 It is an implementation detail. 这是python 3.6的意外情况。这是一个实现细节。 See Dictionaries are ordered in Python 3.6+ 请参阅Python 3.6+中的字典

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM