How about the simple:

for e in ['cc', 'dd',...]: 
  a.pop(e)
Answer from Himadri Choudhury on Stack Overflow
๐ŸŒ
Python Helper
pythonhelper.com โ€บ home โ€บ python dictionary pop() method
Python Dictionary pop(First, Last, Multiple) Items - Python Helper
August 7, 2023 - The corresponding values are then assigned to the variables profession1 and profession2, respectively. By utilizing the pop() method with multiple keys, we can efficiently remove and retrieve multiple items from the dictionary. ... Dictionaries in Python can be nested, meaning they can contain ...
Discussions

python - Fastest way to pop N items from a large dict - Stack Overflow
I have a large dict src (up to 1M items) and I would like to take N (typical values would be N=10K-20K) items, store them in a new dict dst and leave only the remaining items in src. It doesn't mat... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Removing multiple keys from a dictionary safely - Stack Overflow
I know how to remove an entry, 'key' from my dictionary d, safely. You do: if d.has_key('key'): del d['key'] However, I need to remove multiple entries from a dictionary safely. I was thinkin... More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 25, 2012
python - How to pop from a dict while looping? - Stack Overflow
I have a following problem. I have a dictionary dict_a. I would like to go through it and if some condition is met, then I would like to pop the item from the dict_a. When I try this: for key in di... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I pop multiple items from a queue? (python)
filter(lambda x: x < 50, xs) where xs is your collection of numbers. Documentation . More on reddit.com
๐ŸŒ r/CodingHelp
3
1
October 9, 2022
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-remove-multiple-keys-from-dictionary
Python - Remove Multiple Keys from Dictionary - GeeksforGeeks
July 12, 2025 - This method is efficient as it ... we can remove multiple keys from dictionary. ... We can use the pop() method to remove keys from the dictionary one by one in a loop....
๐ŸŒ
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 - The pop() method removes the item associated with the specified key from the dictionary and returns its value. Built-in Types - dict.pop() โ€” Python 3.13.3 documentation
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ pop-python
How to Use `.pop()` in Python Lists and Dictionaries | DigitalOcean
Learn how to use the .pop() method in Python to remove items from lists and dictionaries. Includes syntax, examples, differences from remove(), edge caseโ€ฆ
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_dictionary_pop.asp
Python Dictionary pop() Method
Python Examples Python Compiler ... 1964 } car.pop("model") print(car) Try it Yourself ยป ยท The pop() method removes the specified item from the dictionary....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-dictionary-pop-method
Python Dictionary pop() Method - GeeksforGeeks
May 9, 2025 - The Python pop() method removes and returns the value of a specified key from a dictionary. If the key isn't found, you can provide a default value to return instead of raising an error.
Top answer
1 of 3
19

A simple comprehension inside dict will do:

dict(src.popitem() for _ in range(20000))

Here you have the timing tests

setup = """
src = {i: i ** 3 for i in range(1000000)}

def method_1(d):
  dst = {}
  while len(dst) < 20000:
      item = d.popitem()
      dst[item[0]] = item[1]
  return dst

def method_2(d):
  return dict(d.popitem() for _ in range(20000))
"""
import timeit
print("Method 1: ", timeit.timeit('method_1(src)', setup=setup, number=1))

print("Method 2: ", timeit.timeit('method_2(src)', setup=setup, number=1))

Results:

Method 1:  0.007701821999944514
Method 2:  0.004668198998842854
2 of 3
12

This is a bit faster still:

from itertools import islice
def method_4(d):
    result = dict(islice(d.items(), 20000))
    for k in result: del d[k]
    return result

Compared to other versions, using Netwave's testcase:

Method 1:  0.004459443036466837  # original
Method 2:  0.0034434819826856256 # Netwave
Method 3:  0.002602717955596745  # chepner
Method 4:  0.001974945073015988  # this answer

The extra speedup seems to come from avoiding transitions between C and Python functions. From disassembly we can note that the dict instantiation happens on C side, with only 3 function calls from Python. The loop uses DELETE_SUBSCR opcode instead of needing a function call:

>>> dis.dis(method_4)
  2           0 LOAD_GLOBAL              0 (dict)
              2 LOAD_GLOBAL              1 (islice)
              4 LOAD_FAST                0 (d)
              6 LOAD_ATTR                2 (items)
              8 CALL_FUNCTION            0
             10 LOAD_CONST               1 (20000)
             12 CALL_FUNCTION            2
             14 CALL_FUNCTION            1
             16 STORE_FAST               1 (result)

  3          18 SETUP_LOOP              18 (to 38)
             20 LOAD_FAST                1 (result)
             22 GET_ITER
        >>   24 FOR_ITER                10 (to 36)
             26 STORE_FAST               2 (k)
             28 LOAD_FAST                0 (d)
             30 LOAD_FAST                2 (k)
             32 DELETE_SUBSCR
             34 JUMP_ABSOLUTE           24
        >>   36 POP_BLOCK

  4     >>   38 LOAD_FAST                1 (result)
             40 RETURN_VALUE

Compared with the iterator in method_2:

>>> dis.dis(d.popitem() for _ in range(20000))
  1           0 LOAD_FAST                0 (.0)
        >>    2 FOR_ITER                14 (to 18)
              4 STORE_FAST               1 (_)
              6 LOAD_GLOBAL              0 (d)
              8 LOAD_ATTR                1 (popitem)
             10 CALL_FUNCTION            0
             12 YIELD_VALUE
             14 POP_TOP
             16 JUMP_ABSOLUTE            2
        >>   18 LOAD_CONST               0 (None)
             20 RETURN_VALUE

which needs a Python to C function call for each item.

Find elsewhere
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ how to remove multiple keys from a python dictionary
How to Remove Multiple Keys from a Python Dictionary - Be on the Right Side of Change
September 14, 2022 - Summary: You can use one of these methods to delete multiple keys from a dictionary Python โ€“ (1) Iterate across the list of keys to be deleted and use the syntax del dict[โ€˜keyโ€™] (2) Iterate across the list of keys to be deleted and call the dictionary.pop(key)method.
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ 102a5c09-d0fd-4d74-b116-a7f25cb8d9fe โ€บ 972d480a-794b-4a56-9980-e8fa636afef4 โ€บ 1577d83c-c037-4776-9fb1-ba4b13baa3d4
Learn Deleting Elements with Return Values | Mastering Python Dictionaries
The pop() method in Python dictionaries allows you to remove a key-value pair based on its key and returns the corresponding value. This method is particularly useful when you need to extract and process a value while simultaneously removing ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ dictionary โ€บ pop
Python Dictionary pop()
Online Python Online JavaScript ... Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The pop() method removes and returns an element from a dictionary having the given key....
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard library โ€บ dict โ€บ pop()
Python dict pop() - Remove Key-Value Pair
November 7, 2024 - The pop() method in Python dictionaries is an essential tool for managing key-value pairs. It allows for the removal of a specified key from a dictionary and returns the value associated with that key.
๐ŸŒ
Inspired Python
inspiredpython.com โ€บ tip โ€บ python-dictionary-tricks-popping-items
Python Dictionary Tricks: Popping items โ€ข Inspired Python
>>> d.pop("favorite_language", "Python") 'Python' >>> d['favorite_city'] = "London" >>> d.popitem() ('favorite_city', 'London') โ€œ ยท You can use the pop(key) method to remove (and return) the value of an item in a dictionary.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - Learn how to use Python's pop() method to remove elements from lists and dictionaries, including how to remove items while iterating.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ python-dictionary-pop-function
Python Dictionary pop
September 28, 2018 - TIP: To remove and return the last ... are several ways to remove multiple keys from a dictionary. Among them, using the built-in Python pop() function is the safest way to delete multiple dictionary keys....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-remove-key-from-dictionary
Python Remove Key from Dictionary โ€“ How to Delete Keys from a Dict
February 22, 2023 - When I say "securely," I mean that if the key doesn't actually exist in the dictionary, the code won't throw an error. We'll discover how to accomplish this using the del keyword, the pop() method, and the popitem() method. Finally, you'll see ...
๐ŸŒ
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
We also have a similar process for when we want to remove items and it's called pop and so I'm going to just get rid of the entire line ยท print(teams.get('mets', 'No team found by that name')) And let's see how we can use pop. With Pop, you simply call teams.pop, and then you pass in in a function calls. We're going to use parens here you pass in the name of the element that you want to remove from the dictionary so I can pass in that name and then pass in a default value if that name isn't found.