Dictionary keys are stored in insertion order, meaning whenever a new key is added it gets added at the very end.

Read the full article: How to sort a dictionary in Python
▸ trey.io/TLDN0N

#Python

@peterdrake that's right.

There are a few features that work differently or only exist on OrderedDict (equality comparisons require the same order for example). I never really used those much though so I haven't really used OrderedDict since Python 3.6.

@treyhunner I haven't used it explicitly, but [the initializer for] the csv package's DictReader class used to return OrderedDicts. It looks like that changed in 3.8:

docs.python.org/3/library/csv.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.