How can I remove a key from a Python dictionary?
Asked 07 September, 2021
Viewed 2.8K times
  • 63
Votes

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?

13 Answer