ProgrammingHardTCS NQT · Wipro pattern

Which statement about dictionary iteration order in Python 3.7 and later is correct?

  1. A. Iteration follows sorted key order
  2. B. Iteration order changes between runs
  3. C. Only integer keys keep their insertion order
  4. D. Iteration follows insertion order

Correct answer: D. Iteration follows insertion order

Dicts keep the order in which keys were first inserted, a guarantee since Python 3.7. Sorting, hash randomisation and key type do not change this.

More Python Programming questions

Exams that ask this topic