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
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
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
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
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-item-from-dictionary-by-key
Python Remove Item from Dictionary by Key - GeeksforGeeks
July 23, 2025 - It is less efficient because it creates a new dictionary, requiring additional memory and processing time. popitem() method removes the last inserted key-value pair from the dictionary.
🌐
W3Schools
w3schools.com › python › gloss_python_remove_dictionary_items.asp
Python Removing Items from a Dictionary
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
🌐
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 - In Python, you can remove an item (key-value pair) from a dictionary (dict) using the pop(), popitem(), clear() methods, or the del statement. You can also remove items based on specific conditions us ...
Find elsewhere
🌐
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.
🌐
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.
🌐
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.
🌐
Educative
educative.io › answers › how-to-remove-items-from-a-dictionary-in-python
How to remove items from a dictionary in Python
The del keyword method uses the keyword from the dictionary to remove an item. ... The clear() method clears all the items in 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)
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
Extracting a value for a non-existent key by subscripting (d[key]) raises a KeyError. To avoid getting this error when trying to access a possibly non-existent key, use the get() method instead, which returns None (or a specified default value) if the key is not in the dictionary.
🌐
Devcamp
bottega.devcamp.com › full-stack-development-javascript-python › guide › overview-multiple-methods-deleting-items-python-dictionary
Overview of the Multiple Methods for Deleting Items in a Python Dictionary
So pop works in a very similar way as the get function with the key difference simply being that it also has the side effect of removing that element from the dictionary and so whenever I'm working with a dictionary in python and I want to remove an element and I want to have access to it and have the ability to have a default in case there was not a key by that name inside the dictionary then pop is a great option so I highly recommend for you to experiment with using both delete and pop to see which one you prefer.
🌐
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…
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › dictionary python remove
Dictionary Python Remove
November 20, 2023 - For the key that you want to remove, it will delete the pair. It will also return the value of the key passed. Answer: This method will empty the dictionary by deleting all the key-value pairs. Answer: KeyError will be thrown that can be handled using the try-catch block. Python dictionary stores key-value mutable pair mappings.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-item-from-dictionary-by-value
Python Remove Item from Dictionary by Value - GeeksforGeeks
July 23, 2025 - If a key is found, the del statement removes the corresponding key-value pair. This method avoids unnecessary iteration if the value is found early. This approach involves iterating through the dictionary to find the key with the specified value ...
🌐
Tutorialspoint
tutorialspoint.com › python › python_remove_dictionary_items.htm
Python - Remove Dictionary Items
The del keyword in Python is used to delete objects. In the context of dictionaries, it is used to remove an item or a slice of items from the dictionary, based on the specified key(s).
🌐
DevGenius
blog.devgenius.io › different-ways-to-remove-dictionary-elements-in-python-30afe788fa50
Efficient Dictionary Element Removal Methods in Python | by Mustafa Celik | Dev Genius
August 13, 2023 - my_dict = {'a': 1, 'b': 2, 'c': ... print(removed_item) # Output: ('c', 3) ... You can create a new dictionary excluding the item you want to remove using a dictionary comprehension....