ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
d = dict(zip('abc', range(3)))
print(d.popitem(), d)
  1. A. ('c', 2) {'a': 0, 'b': 1, 'c': 2}
  2. B. ('b', 1) {'a': 0, 'c': 2}
  3. C. ('c', 2) {'a': 0, 'b': 1}
  4. D. ('a', 0) {'b': 1, 'c': 2}

Correct answer: C. ('c', 2) {'a': 0, 'b': 1}

popitem removes the last inserted key-value pair, which is ('c', 2), since dicts keep insertion order.

More Python Programming questions

Exams that ask this topic