Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

How to Remove an Item from a Dictionary in Python

Use del to remove a dictionary entry by key, or pop to remove it and return its value. Learn what happens with missing keys and how to remove pairs or clear a dictionary.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To remove a dictionary entry by its key, use del my_dict[key]. If you also need the removed value, use my_dict.pop(key). Both raise KeyError when the key is missing; pop can instead return a fallback if you provide one.

Remove an entry by key

A dictionary entry consists of a key and its associated value. Python removes the entry by key—not by searching for its value. Use del when you only need to delete the entry:

person = {"name": "Ada", "age": 36}
del person["age"]

print(person)  # {'name': 'Ada'}

del person["age"] changes the existing dictionary in place. It raises KeyError if "age" is not a key in the dictionary.

Choose the removal method you need

Need Operation What happens
Delete a known key without using its value del d[key] Removes the entry; raises KeyError if the key is absent.
Delete a key and retrieve its value d.pop(key) Removes and returns the value; raises KeyError if the key is absent.
Delete a key only if present d.pop(key, default) Removes and returns the value if present; otherwise returns default.
Remove the most recently inserted entry d.popitem() Removes and returns a (key, value) pair; raises KeyError if the dictionary is empty.
Remove every entry d.clear() Empties the dictionary.

These operations and their behavior are documented in the Python 3.14.8 built-in types reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use pop when you need the removed value

pop removes the entry and returns its value, which is useful when the value should be saved or used immediately:

person = {"name": "Ada", "age": 36}
name = person.pop("name")

print(name)    # Ada
print(person)  # {'age': 36}

To avoid an error when a key may be absent, pass a default:

age = person.pop("age", None)

If "age" is missing, this returns None without changing the dictionary. Use this form only when None is an acceptable fallback. If None could also be a stored value and you need to tell that apart from a missing key, use a unique sentinel:

missing = object()
value = person.pop("age", missing)

if value is missing:
    print("No age entry")

Remove the latest entry or empty the dictionary

Remove the most recently inserted pair

Call popitem() when you want to remove and receive the most recently inserted key-value pair:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
last_key, last_value = person.popitem()

Dictionaries preserve insertion order, and popitem() removes pairs in last-in, first-out order in current Python; that order has been guaranteed since Python 3.7. Calling it on an empty dictionary raises KeyError.

Remove all entries

Call clear() to empty the dictionary in place:

person.clear()

Afterward, the dictionary still exists, but it contains no entries.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Removing an entry by its value

del and pop take a key, not a value. Python dictionaries do not provide a remove(value) method. If your goal is to exclude entries with a particular value, build a new dictionary by filtering its items:

scores = {"Ada": 10, "Lin": 7, "Sam": 10}
without_tens = {
    key: value
    for key, value in scores.items()
    if value != 10
}

print(without_tens)  # {'Lin': 7}

This creates a new dictionary and leaves scores unchanged. The dictionary removal operations are described in the official Python documentation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.