Repaso
Español
PythonIntermediatePY-19

Since which Python version is insertion order of dict guaranteed by the language spec?

Options

  1. 2.7
  2. 3.5
  3. 3.7 (Correct option)
  4. 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+).

Key terms

Practice this question in Repaso