ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
d = {"a": 1, "b": 2, "c": 3}
del d["a"]
d["a"] = 4
d.pop("b")
d["b"] = 5
print(list(d.items()), next(iter(d)), next(reversed(d)))
  1. A. [('c', 3), ('a', 4), ('b', 5)] c b
  2. B. [('a', 4), ('b', 5), ('c', 3)] a c
  3. C. [('c', 3), ('a', 4), ('b', 5)] c c
  4. D. [('a', 4), ('c', 3), ('b', 5)] a b

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

Deleting a key and inserting it again puts it at the end of the insertion order. Since Python 3.8, dicts and their views support reversed().

More Python Programming questions

Exams that ask this topic