UseYou can use a dictionary comprehension to create a new dictionary with that key removed:
>>> if myDict.get(key):my_dict myDict.pop(key)
Another way:
>>>= {k: v for k, v in myDictmy_dict.items() if k != 'key'}
You can delete by conditions. No error if key doesn't exist.