Is there a one-line way of deleting a key from a dictionary without raising a KeyError?

if 'key' in my_dict:
    del my_dict['key']

1
15

Leave a Reply

Your email address will not be published. Required fields are marked *