Python Dictionary popitem() Method
Removes the last key-value pair that was inserted and returns that key-value pair as a tuple.
Syntax
Python
Copy Code
dictionary.popitem()
Example
Python
Copy Code
fish = { 'guppy': 2, 'zebra': 5, 'betta': 10 } lastItem = fish.popitem() print(fish) print(f'I no longer have {lastItem}')
Output
{'guppy': 2, 'zebra': 5} I no longer have ('betta', 10)