When deleting a key from a dictionary, I use:
if \'key\' in my_dict:
del my_dict[\'key\']
Is there a one line way of doing this?
It took me some time to figure out what exactly my_dict.pop("key", None) is doing. So I'll add this as an answer to save others Googling time:
pop(key[, default])If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a
KeyErroris raised.
Documentation