Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: What is printed by this snippet? d = {} d['b'] = 1 d['a'] = 2 d['b'] = 3 print(list(d.items()))

  1. A. [('a', 2), ('b', 3)]
  2. B. [('b', 1), ('a', 2)]
  3. C. [('a', 2), ('b', 1)]
  4. D. [('b', 3), ('a', 2)]

Correct answer: D. [('b', 3), ('a', 2)]

Python dicts keep insertion order, and reassigning an existing key does not move it. The output lists 'b' first with its updated value 3.

More Coding Interview Problems questions

Exams that ask this topic