dict.pop vs dict.popitem: Removing items from a Python dictionary

dict.pop vs dict.popitem: Removing items from a Python dictionary

Differences between dict.pop and dict.popitem in Python:

dict.pop:

– removes a pair based on a key
– returns removed value
– optional 2nd arg is returned if key isn’t there

dict.popitem:

– no arguments
– returns the most-recently-inserted pair
– returns (key, value) tuple