Since which Python version is insertion order of dict guaranteed by the language spec?
Options
- 2.7
- 3.5
- 3.7 (Correct option)
- 3.10
Answer
3.7
Why
Since Python 3.7 the language guarantees that a dict remembers the order in which keys were added, and loops return keys in that order.
CPython 3.6 already did this, but only as an implementation detail you could not rely on.
Remember
Dicts keep insertion order (3.7+).