The popitem() method removes the last item inserted in a dictionary.
The method returns the removed item as a tuple.
In this example, a have a dictionary named people with three items, 'Sarah':32 is the last one.
When I use popitem() in the dictionary, the item corresponding to ‘Sarah’ is removed.
people = {'Bob':30, 'Mary':25, 'Sarah':32}
person = people.popitem()
print(person)
print(people)('Sarah', 32)
{'Bob': 30, 'Mary': 25}To learn more about dictionaries, read this post Python Dictionary: a quick reference.