Well, you could do this:

>>> if all(k in foo for k in ("foo","bar")):
...     print "They're there!"
...
They're there!
Answer from hughdbrown on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-check-if-given-multiple-keys-exist-in-a-dictionary
Python | Check if given multiple keys exist in a dictionary - GeeksforGeeks
July 11, 2025 - Method #3 Using if and all statement : In this method we will check that if all the key elements that we want to compare are present in our dictionary or not . ... # Python3 code check multiple key existence # using if and all # initializing ...
Discussions

Most Python way to check if one or multiple keys match in a dictionary?
What about if {keyname1, keyname2}.issubset(mydict): otherwise you're stuck with multiple ifs if keyname1 in mydict and keyname2 in mydict: or comprehended if all(k in mydict for k in (keyname1, keyname2)): More on reddit.com
🌐 r/learnpython
11
3
December 10, 2018
python - Check if dictionary has multiple keys - Stack Overflow
How can I check if a dictionary (actually dictionary-like object) has all of a given set of keys (plural)? ... d = { 'a': 1, 'b': 2, 'c': 3 } keys = ('a', 'b') def has_keys(d, keys): for key in keys: if not key in d: return False return True · Is there a more elegant and Pythonic way of doing this? More on stackoverflow.com
🌐 stackoverflow.com
python: what is best way to check multiple keys exists in a dictionary? - Stack Overflow
my dict looks like d = { 'name': 'name', 'date': 'date', 'amount': 'amount', ... } I want to test if name and amount exists, so I will do if not `name` in d and not `amount` in d: raise More on stackoverflow.com
🌐 stackoverflow.com
April 15, 2013
Check multiple `keys` in Python dictionary - Stack Overflow
Basically, what I'm trying to achieve is check from 1st condition to n-1 and return the result when Key is matching otherwise return the last value. More on stackoverflow.com
🌐 stackoverflow.com
🌐
w3resource
w3resource.com › python-exercises › dictionary › python-data-type-dictionary-exercise-33.php
Python: Check multiple keys exists in a dictionary - w3resource
June 28, 2025 - Write a Python program to verify if a list of keys are all present in a dictionary. Write a Python program to use all() with a list comprehension to check for multiple keys in a dictionary.
🌐
TutorialsPoint
tutorialspoint.com › article › check-if-given-multiple-keys-exist-in-a-dictionary-in-python
Check if given multiple keys exist in a dictionary in Python
May 13, 2020 - This approach uses a generator expression with the all() function to check if every key exists in the dictionary.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-check-if-multiple-keys-in-dict
Check if multiple Keys exist in a Dictionary in Python | bobbyhadz
April 9, 2024 - Use the dict.keys() method to get a view of the dictionary's keys. Check if the multiple keys are present in the view of the dictionary's keys.
🌐
Reddit
reddit.com › r/learnpython › most python way to check if one or multiple keys match in a dictionary?
r/learnpython on Reddit: Most Python way to check if one or multiple keys match in a dictionary?
December 10, 2018 -

Hello Reddit,

For a single key to match it very easy to check of the key is available:

if "keyname" in mydict:
    #do something with if this key matches

To check if multiple keys are in the dict:

if {"keyname1", "keyname2"}.issubset(mydict):
    #do something if both are in the dict

What I want is to check if one or two are in the dict:

if "keyname1" or "keyname2" in dict:
    #this will not work as it will check: 
    #    ("keyname1") or ("keyname2" in dict) and not 
    #    ("keyname1" or "keyname2") in dict
    #do something if one or more of them matches

How do I achieve this?

🌐
Python Guides
pythonguides.com › python-dictionary-multiple-keys
How To Select Multiple Keys From A Dictionary In Python?
March 18, 2025 - All four are fast; itemgetter is quickest because the loop runs in C. Choose the one that reads best unless it runs millions of times. If you meant one entry identified by several values, such as a pair of cities, use a tuple as the key. Tuples are hashable, lists aren’t: # a dictionary with multiple keys per entry: use a tuple as the key distances = { ("London", "Paris"): 344, ("London", "Berlin"): 932, ("Paris", "Berlin"): 878, } print(distances[("London", "Paris")]) print(distances.get(("Paris", "Rome"), "unknown")) # all entries that start in London print({k: v for k, v in distances.items() if k[0] == "London"})
Find elsewhere
🌐
YouTube
youtube.com › watch
3 ways to check for multiple keys in a Python dictionary - YouTube
In this video we show you 3 ways to check for multiple keys in a dictionary:- Use in multiple times- Use the all() built-in function- Use set operations, spe...
Published: April 17, 2023
🌐
Tutorjoes
tutorjoes.in › Python_example_programs › check_multiple_key_exixts_dict_in_python
Write a Python program to check multiple keys exists in a dictionary
The program demonstrates the use of the &ht;= operator in the context of dictionaries. The &ht;= operator checks whether the set on the left side is a superset of the set on the right side, which means that all elements in the set on the right side are also in the set on the left side.
🌐
Bomberbot
bomberbot.com › python › mastering-multiple-key-checks-in-python-dictionaries
Mastering Multiple Key Checks in Python Dictionaries - Bomberbot
This method converts the dictionary keys and the keys to check into sets, then uses the issubset() method to check if all required keys are present. Set operations in Python are highly optimized and can provide significant performance benefits, especially for large datasets.
🌐
Let's Data Science
letsdatascience.com › home › questions › 87. checking multiple keys in dictionary
87. Checking Multiple Keys in Dictionary - Let's Data Science
August 4, 2023 - Write a Python function that takes a dictionary and a list of keys as parameters. The function should return True if all keys in the list are present in the dictionary, otherwise, return False. ... Use Python’s all function and list comprehension to check for multiple keys in the dictionary.
🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-how-to-check-if-multiple-keys-exist-in-dict
How to Check for Multiple Keys in a Python Dictionary | Tutorial Reference
The most Pythonic and generally efficient way to check for multiple keys is to use the all() function with a generator expression: ... keys_to_check = ("name", "country"): We define a tuple containing the keys we want to check. Using a tuple is slightly more efficient than a list for this purpose, ...
🌐
Iditect
iditect.com › faq › python › how-to-check-that-multiple-keys-are-in-a-dict-in-a-single-pass-using-python.html
How to check that multiple keys are in a dict in a single pass using python?
To check if multiple keys exist in a dictionary in a single pass in Python, you can use the all() function in combination with a generator expression.
🌐
Stack Overflow
stackoverflow.com › questions › 43346000 › how-to-check-for-multiple-keys-in-a-dictionary-and-then-do-something-with-each
python 2.7 - How to check for multiple keys in a dictionary, and then do something with each of them? - Stack Overflow
if key1 in data and key2 in data: val1 = data[key1] val2 = data[key2] ... Sign up to request clarification or add additional context in comments. ... Amplitude modulating a 14Vpp carrier wave with a 12Vpp modulating wave with a diode modulation circuit results in a signal less than 360mVpp ... Dealing with incompatible output geometry after geospatial operations using WKBType checks in PyQGIS ... Why does my Highlander Hybrid start and stop the engine multiple times rapidly at a traffic light at the bottom of a hill?
🌐
Omics
python.omics.wiki › data-structures › dictionary › multiple-keys
Python by Examples - Multiple keys
Multi-key combinations to access values a) Table/matrix representation using tupels Tupels are 'hashable' objects and hence can be used as a key in python dictionaries. {(key_part_1, key_part_2):