The del statement removes an element:

del d[key]

Note that this mutates the existing dictionary, so the contents of the dictionary changes for anybody else who has a reference to the same instance. To return a new dictionary, make a copy of the dictionary:

def removekey(d, key):
    r = dict(d)
    del r[key]
    return r

The dict() constructor makes a shallow copy. To make a deep copy, see the copy module.


Note that making a copy for every dict del/assignment/etc. means you're going from constant time to linear time, and also using linear space. For small dicts, this is not a problem. But if you're planning to make lots of copies of large dicts, you probably want a different data structure, like a HAMT (as described in this answer).

Answer from Greg Hewgill on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_dictionaries_remove.asp
Python - Remove Dictionary Items
MongoDB Get Started MongoDB Create DB MongoDB Collection MongoDB Insert MongoDB Find MongoDB Query MongoDB Sort MongoDB Delete MongoDB Drop Collection MongoDB Update MongoDB Limit · Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary
Discussions

Delete item from dict Python
d = {k:v for k,v in defalutdict.items() if 'UP' not in k} More on reddit.com
🌐 r/learnpython
27
1
July 28, 2021
Python - How to delete an item/value from a key in a dictionary?
If you want to remove the value but keep the key, set the value for the key to something like 'None' More on reddit.com
🌐 r/learnprogramming
9
2
November 13, 2022
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
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
0
0
March 2, 2024
🌐
AskPython
askpython.com › home › ways to delete a dictionary in python
Ways to Delete a Dictionary in Python - AskPython
February 16, 2023 - Python popitem() function can be used to delete a random or an arbitrary key-value pair from a Python dict. The popitem() function accepts no arguments and returns the deleted key-value pair from the dictionary.
🌐
Reddit
reddit.com › r/learnpython › delete item from dict python
r/learnpython on Reddit: Delete item from dict Python
July 28, 2021 -

Hello,

I have this dictionary:

defaultdict={'UP 1': 1, 'P sMaple-sMary': 36, 'UP sMaple': 14, 'UP sMary': 32, 'P sJewell-sCynthia': 3, 'UP sJewell': 0, 'UP sCynthia': 4, 'P sPamela-sRachel': 1, 'UP sPamela': 0, 'UP sRachel': 0, 'P sSylvia-sElsie': 1, 'UP sSylvia': 0, 'UP sElsie': 5, 'P sMarcelene-sMaria': 7, 'UP sMarcelene': 5}

And I want to remove item if it starts UP. I tried the following code but it does not work

key_to_remove="UP"
del defaultdict[key_to_remove] #I tried to remove
res2 = Counter(defaultdict.values()) 3after removing, I wanted to count each value
print(res2)
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 - Let's get started! The most popular method for removing a key:value pair from a dictionary is to use the del keyword. You can also use it to eliminate a whole dictionary or specific words.
🌐
Medium
medium.com › @adarshp24comp › accessing-updating-and-deleting-dictionary-items-in-python-f3aa08a157dd
Accessing, Updating, and Deleting Dictionary Items in Python | by Adarsh Anil Patil | Medium
October 30, 2025 - There are multiple ways to remove items from a dictionary: ... {'name': 'Adarsh', 'age': 21, 'course': 'Computer Science', 'marks': 95, 'email': 'adarsh@gmail.com'} If you try to delete a key that doesn’t exist, Python will raise a KeyError.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-remove-a-key-from-dictionary
Python - Ways to remove a key from dictionary - GeeksforGeeks
October 29, 2025 - Python · a = {"name": "Nikki", ... after using the pop() method, key - "age" is completely removed from the dictionary. del() statement deletes a key-value pair from the dictionary directly and does not return the value making ...
🌐
Vultr
docs.vultr.com › python › examples › delete-an-element-from-a-dictionary
Python Program to Delete an Element From a Dictionary | Vultr Docs
December 5, 2024 - In this article, you will learn how to delete elements from a dictionary in Python using various methods. These techniques include using the del keyword, the pop() method, and the popitem() method.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Remove an Item from a Dictionary in Python: pop, popitem, clear, del | note.nkmk.me
April 27, 2025 - Built-in Types - dict.clear() — Python 3.13.3 documentation · d = {'k1': 1, 'k2': 2, 'k3': 3} d.clear() print(d) # {} ... The del statement can also be used to delete an item from a 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 existing item (so a .get() and ‘del item’ combined).
🌐
Python Engineer
python-engineer.com › posts › delete-key-dictionary
How to delete a key from a dictionary in Python - Python Engineer
This article shows how you can remove a key from a dictionary in Python. To delete a key, you can use two options: Using del my_dict['key'] Using my_dict.pop('key', None) Let's look at both options in detail: #more ·
🌐
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...
🌐
Sentry
sentry.io › sentry answers › python › delete element from a dictionary in python
Delete element from a dictionary in Python | Sentry
August 15, 2023 - To delete an element from a dictionary, we can use the del keyword. For example: products = {"apples": 1, "oranges": 3, "pears": 2} print(products) # will print the dictionary defined above del products["oranges"] print(products) # will print ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-removing-dictionary-from-list-of-dictionaries
Removing Dictionary from List of Dictionaries - Python - GeeksforGeeks
July 11, 2025 - Using list comprehension, we can filter the list while excluding dictionaries that meet the condition.
🌐
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.