What is the output of the following Python code snippet?
d = {'a': 1, 'b': 2}
print(d.popitem())
print(d.popitem())
Correct answer
C. ('b', 2)
C. ('b', 2)
popitem() removes and returns the last inserted item (LIFO) in Python 3.7+.
Asked in: Python Interview Dictionaries
https://docs.python.org/3/tutorial/datastructures.html#dictionariesNot sure why the answer is C? Ask here and get an explanation.