dict.popitem()
dict.popitem() is a Python method in the Dictionary Methods category. Removes and returns the last inserted (key, value) pair as a tuple. The syntax is dict.popitem(). Returns: (key, value) tuple. A typical example: d = {"a": 1, "b": 2}
d.popitem() # ("b", 2) (Python 3.7+). A close sibling is dict.get(), which returns the value for key if it exists, otherwise returns default. A close sibling is dict.keys(), which returns a view object of all keys in the dictionary. A close sibling is dict.values(), which returns a view object of all values in the dictionary. A close sibling is dict.items(), which returns a view object of all (key, value) pairs as tuples. More about this category: Dictionary methods for key-value operations — get, keys, items, update, and more. For a broader walkthrough, read the Dictionary Methods guide. Related Dictionary Methods entries: dict.get(), dict.keys(), dict.values(), dict.items(), dict.update(), dict.pop().