ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
d = {"a": 1, "b": 2, "c": 3}
d["a"] = 10
del d["b"]
d["b"] = 20
d.update({"a": 0, "z": 9})
print(list(d), d.popitem())
  1. A. ['a', 'b', 'c', 'z'] ('z', 9)
  2. B. ['c', 'b', 'a', 'z'] ('z', 9)
  3. C. ['a', 'c', 'b', 'z'] ('z', 9)
  4. D. ['a', 'c', 'b', 'z'] ('a', 0)

Correct answer: C. ['a', 'c', 'b', 'z'] ('z', 9)

Updating an existing key keeps its original position; deleting and re-inserting moves a key to the end. popitem() removes the most recently inserted pair (LIFO), which is ('z', 9).

More Python Programming questions

Exams that ask this topic