The popitem Method in Python: Removing the Last Key-Value Pair
Returns and removes the last added key-value pair in a dictionary.
popitem()
a = {'one': 1, 'two': 2, 'three': 3}
print(a.popitem()) # Output: ('three', 3), a = {'one': 1, 'two': 2}
print(a.popitem()) # Output: ('two', 2), a = {'one': 1}
a['four'] = 4
print(a.popitem()) # Output: ('four', 4), a = {'one': 1}