ProgrammingVery hardPython · GATE DA · Advanced

What is printed?

What is printed?
d = {'a': 1, 'b': 2, 'c': 3}
del d['a']
d['a'] = 0
d |= {'b': 9, 'z': 4}
print(list(d.items()), min(d, key=d.get))
  1. A. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] a
  2. B. [('a', 0), ('b', 9), ('c', 3), ('z', 4)] a
  3. C. [('c', 3), ('a', 0), ('b', 9), ('z', 4)] a
  4. D. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] c

Correct answer: A. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] a

A deleted and re-added key goes to the end; |= updates existing b in place (keeping its position) and appends new z. min by value picks 'a' (0).

More Python Programming questions

Exams that ask this topic