To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop():

my_dict.pop('key', None)

This will return my_dict[key] if key exists in the dictionary, and None otherwise. If the second parameter is not specified (i.e. my_dict.pop('key')) and key does not exist, a KeyError is raised.

To delete a key that is guaranteed to exist, you can also use

del my_dict['key']

This will raise a KeyError if the key is not in the dictionary.

Answer from Sven Marnach on Stack Overflow
Discussions

Can we have a .delete() for dictionary please
I would like to see a .delete() that doesn’t raise KeyError if the key doesn’t exist. I’m suggesting .delete() so that existing code is not affected. I’m dealing with json input from Grinding Gear Games and i’m getting… More on discuss.python.org
🌐 discuss.python.org
8
0
March 2, 2024
Can we have a .discard() for dictionary please - Ideas - Discussions on Python.org
Ref: https://discuss.python.org/t/can-we-have-a-delete-for-dictionary-please/ In the ref I was given a solution for my problem, which while usable, is not thematically correct. .pop() is for removing and retrieving an existing item (so a .get() and ‘del item’ combined). More on discuss.python.org
🌐 discuss.python.org
1
March 2, 2024
How can I remove keys in a dictionary where the value is empty?
Create a new dictionary: myDict = {key: value for key, value in myDict if value} More on reddit.com
🌐 r/learnpython
14
18
February 25, 2021
How to remove empty dictionary value from list?

Yes the quotes (empty string) are considered values and you would use an if statement. Probably what I would suggest is a list comprehension:

[d for d in mylist if d['name']]

This creates a new list with each dictionary value in there if the value corresponding to the key 'name' is not an empty string. The empty string is a Falsey value in Python, so instead of checking if d['name'] != '' (which is also totally valid) you can just ask if d['name'].

More on reddit.com
🌐 r/learnpython
27
39
January 28, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-remove-a-key-from-dictionary
Python - Ways to remove a key from dictionary - GeeksforGeeks
October 29, 2025 - Explanation: Notice that after using the pop() method, key - "age" is completely removed from the dictionary.
🌐
Python Morsels
pythonmorsels.com › removing-a-dictionary-key
Removing a dictionary key - Python Morsels
January 13, 2023 - To delete a key from a dictionary, you can use Python's del statement or you can use the dictionary pop method.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-remove-key-from-dictionary
Python Remove Key from Dictionary – How to Delete Keys from a Dict
February 22, 2023 - As you can see, the function removed the last key:value pair – 5: "Black" – from the dictionary. You can easily delete multiple keys from a dictionary using Python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-multiple-keys-from-dictionary
Python - Remove Multiple Keys from Dictionary - GeeksforGeeks
July 12, 2025 - We can use the pop() method to remove keys from the dictionary one by one in a loop.
🌐
Medium
medium.com › @python-javascript-php-html-css › efficiently-removing-keys-from-python-dictionaries-5edc9a4ab9b3
Remove Keys from Python Dictionaries Effectively
August 24, 2024 - The most efficient method depends on the specific use case, but dictionary.pop(key, None) is generally a concise and safe option for single key removal. ... Removing keys from a Python dictionary safely and efficiently can be achieved through various methods.
🌐
Python Engineer
python-engineer.com › posts › delete-key-dictionary
How to delete a key from a dictionary in Python - Python Engineer
If key is in the dictionary, it removes it and returns its value, else it returns default. If default is not given and the key is not in the dictionary, a KeyError is raised.
🌐
Python.org
discuss.python.org › python help
Can we have a .delete() for dictionary please - Python Help - Discussions on Python.org
March 2, 2024 - I would like to see a .delete() that doesn’t raise KeyError if the key doesn’t exist. I’m suggesting .delete() so that existing code is not affected. I’m dealing with json input from Grinding Gear Games and i’m getting really sick of this: if gem.get("baseTypeName"): del gem["baseTypeName"] if gem["grantedEffect"].get("baseTypeName"): del gem["grantedEffect"]["baseTypeName"] if gem["secondaryGrantedEffect"].get("baseTypeName"): del gem["secondaryGrantedEffe...
🌐
Codefinity
codefinity.com › courses › v2 › 6f555920-ae38-4413-a9ce-cfa29f4c6e6b › d08da236-e2aa-479b-8926-fc8920a647d4 › 3c174771-beda-49d3-8e02-ebd8fc52d7ad
Learn Removing Dictionary Entries in Python | Section
In Python, you can remove keys from a dictionary using the del keyword. This allows you to delete specific entries or even clear the entire dictionary.
🌐
Python.org
discuss.python.org › ideas
Can we have a .discard() for dictionary please - Ideas - Discussions on Python.org
March 2, 2024 - Ref: https://discuss.python.org/t/can-we-have-a-delete-for-dictionary-please/ In the ref I was given a solution for my problem, which while usable, is not thematically correct. .pop() is for removing and retrieving an …
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › remove multiple keys from python dictionary
Remove Multiple keys from Python Dictionary - Spark By {Examples}
May 31, 2024 - How to remove multiple keys from Python Dictionary? To remove multiple keys you have to create a list or set with the keys you want to delete from a
🌐
Educative
educative.io › answers › how-to-remove-items-from-a-dictionary-in-python
How to remove items from a dictionary in Python
The pop method uses the keyword from the given dictionary to remove an item from that dictionary.
🌐
Scaler
scaler.com › home › topics › remove key from dictionary python
remove key from dictionary python | Scaler Topics
May 4, 2023 - We can use the items() method with a for-loop to remove a key from dictionary in Python. We simply iterate over our current dictionary and copy all key-value pairs (except the key to be deleted) to our new dictionary.
🌐
Stack Abuse
stackabuse.com › python-how-to-remove-a-key-from-a-dictionary
Python: How to Remove a Key from a Dictionary
September 19, 2021 - The pop(key, d) function removes a key from a dictionary and returns its value. It takes two arguments, the key is removed and the optional value to return if the key isn't found.
🌐
Jinja
jinja.palletsprojects.com › en › stable › templates
Template Designer Documentation — Jinja Documentation (3.1.x)
A dict in Python is a structure that combines keys and values. Keys must be unique and always have exactly one value.
🌐
HackerEarth
hackerearth.com › practice › python › working with data › dictionary
Dictionary Tutorials & Notes | Python | HackerEarth
A disadvantage is that it gives KeyError if you try to delete a nonexistent key. >>> # initialise a dictionary with the keys “city”, “name”, “food” >>> person1_information = {'city': 'San Francisco', 'name': 'Sam', "food": "shrimps"} >>> # deleting a non existent key gives key error.