Redcoatwright
Redcoatwright

Reputation: 157

OrderedDict in Python

I'm learning about OrderedDicts in python but when I create new dictionaries it preserves the order anyway. I can't seem to find a good example of why you'd ever need to use an 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}

I'm just looking to understand why we need OrderedDicts.

Upvotes: 1

Views: 95

Answers (1)

Thomas Junk
Thomas Junk

Reputation: 5676

I'm learning about OrderedDicts in python but when I create new dictionaries it preserves the order anyway.

This is accidentally the case with python 3.6 It is an implementation detail. See Dictionaries are ordered in Python 3.6+

Upvotes: 3

Related Questions