Notes and Thoughts

The keeping of a second brain

Home

Python dictionaries are insertion-ordered from 3.7+

They are insertion-ordered in CPython implementation of Python 3.6 as an implementation detail. Guido announced on the mailing list that it is officially part of the language spec in Python 3.7 onwards. From the docs:

Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was implementation detail of CPython from 3.6.

list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order. Sets are still unordered.