If I understand you correctly, you're looking for something like that:

>>> d = {'galaxy': 5, 'apple': 6, 'nokia': 5}
>>> { k:v for k,v in d.items() if v==5 }
{'nokia': 5, 'galaxy': 5}
Answer from Ohad Eytan on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ checking multiple values in dictionary [python]
r/learnprogramming on Reddit: Checking multiple values in dictionary [Python]
April 18, 2021 -

For example, given the dictionary:

dict = {

character1: ['assassin', 'mage'] , character2:['assassin', 'fighter'] , character3:['assassin' ]

}

what would be the best way to append all the keys that contain the value 'assassin' , but do not contain other values, such as "mage" and "fighter"?

I figured i could just do this:

assassins = []
for x in dict:
    if "assassins" in dict[x] and "mage" not in dict[x] and "fighter" not in             
dict[x]:
            assassins.append(x)

but i feel like there's a better way.

Discussions

Key with multiple values - check if value is in dictionary python - Stack Overflow
I have a dictionary that has a list of multiple values stored for each key. I want to check if a given value is in the dictionary, but this doesn't work: if 'the' in d.values(): print "value in More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 22, 2017
python - Dictionaries - Check key for multiple values - Stack Overflow
In that case how can i check for multiple items in the list that is my value? ... You should be more specific with your problem. Dictionaries can only have one value per key, if you try to assign a second value, the first will be overwritten. Are your values lists? ... yes, it seems my values are lists. thank you for the clarification. i will edit my post to specify/correct my question. ... Using the len builtin in python... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 6, 2016
How to check if multiple values exists in a dictionary python - Stack Overflow
def check_value_exist(test_dict, ... {value1, value2} <= test_dict.keys() ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Stack Overflow chat opening up to all users in January; Stack Exchange chat... 20 python: what is best way to check multiple keys exists in a dictionary... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to search for multiple values in a dictionary in python? - Stack Overflow
I am new to coding... I have to create a dictionary from a database (which I believe I was able to do so) but I haven't found any example on how to search for multiple values. In this case I want the More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-check-if-given-multiple-keys-exist-in-a-dictionary
Python | Check if given multiple keys exist in a dictionary | GeeksforGeeks
April 27, 2023 - Auxiliary space: O(n), as we are creating a dictionary with n key-value pairs. 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 a dictionary sports = {&quot;geeksforgeeks&quot; : 1, &quot;practice&quot; : 2, &quot;contribute&quot; :3} # using if, all statement if all(key in sports for key in ('geeksforgeeks', 'practice')): print(&quot;keys are present&quot;) else: print(&quot;keys are not present&quot;) # using if, all statement if all(key in sports for key in ('geeksforgeeks', 'ide')): print(&quot;keys are present&quot;) else: print(&quot;keys are not present&quot;)
๐ŸŒ
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 use all() with a list comprehension to check for multiple keys in a dictionary. Write a Python program to implement a function that returns True if every key in a given list exists in the 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 - Set comparison with >= operator offers the best combination of readability and performance for checking multiple key existence.
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ check if value exists in a dictionary in python
Check if Value Exists in a Dictionary in Python - PythonForBeginners.com
June 1, 2022 - The dictionary is: {'name': 'Python ... we are given multiple values to check for their presence, we will use a for loop with the membership operator and the values() method to check for the presence of the keys....
Find elsewhere
Top answer
1 of 2
2

Using the len builtin in python, you can check the length of a list. If the length of the value is more then 1 then there are more then one value in the list.

for key in dictionary: # loop through all the keys
    value = dictionary[key]   # get value for the key
    if len(value) > 1:        
        break                 # stop loop if list length is more than 1

Note that this assumes that every value in the dictionary is a list or container.

2 of 2
1

It is not possible for a dictionary key to have more than one value: either the key is not present in the dictionary, so it has no value, or it is present, and it has one value.

That value may be a tuple, list, dictionary, etc., which contains multiple values, but it is still one value itself. The value may also be None which can be a marker for no value, but it is still a value.

As @Ulisha's comment said, if you try to assign a new value to a key, the new value will just replace the old value. Again, there can be at most one value for a given key, although there are ways to simulate multiple values by using container objects such a tuple, list, or dict.


If you are looking at a specific item and you want to test if it is a list, you can use

if isinstance(item, list):

This will also catch items that have a type that descends from list, such as a priority queue. If you want to expand that to also detect tuples, dicts, sets, and most other "containers", you can use

if isinstance(item, collections.Container):

For this you will, of course, need to import the collections module.

Remember that even if the item is a list, it may have no, one, or multiple items.

๐ŸŒ
Quora
quora.com โ€บ What-is-the-best-approach-to-checking-if-multiple-conditions-exist-in-a-Python-list-of-dictionaries-Please-see-my-response-for-details
What is the best approach to checking if multiple conditions exist in a Python list of dictionaries? Please see my response for details. - Quora
How do you iterate over list type values in a Python dictionary to see if at least one element in the first list exists in the second list? How do you update an element in a nested list/dictionary in Python? How do you convert a string (that should basically be a list of dictionaries) to a list Of dictionaries (Python, Python 3.x, string, list, dictionary, development)? How do I flatten a nested list to a dictionary in Python? How do I check ...
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ search-for-value-in-the-python-dictionary-with-multiple-values-for-a-key
Search for Value in the Python Dictionary with Multiple Values for a Key - GeeksforGeeks
February 8, 2024 - # Using defaultdict from collections ...extend([92, 88, 95]) def search_value(dictionary, key, target_value): if key in dictionary: values = dictionary[key] if target_value in values: return True return False # printing output result ...
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-get-multiple-values-from-dictionary
Get multiple values from a Dictionary in Python | bobbyhadz
April 9, 2024 - Copied!my_dict = { 'name': 'Borislav ... dictionary a KeyError exception is raised. You can use an if statement to check if the key is present in the dictionary before accessing it....
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 63553540 โ€บ how-to-search-for-multiple-values-in-a-dictionary-in-python
How to search for multiple values in a dictionary in python? - Stack Overflow
Dictionary are made for key โ†’ value lookups. Searching for values is not efficient but possible by iterating through all items and applying a condition manually.
๐ŸŒ
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?

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 51653771 โ€บ check-for-multiple-integer-values-in-dictionary-where-dictionary-values-are-list
python - Check for multiple integer values in dictionary where dictionary values are lists of integers - Stack Overflow
Better: sum({2, 3}.issubset(x) for x in d.values()). No need to create an intermediary list. 2018-08-02T13:05:09.063Z+00:00 ... Save this answer. ... Show activity on this post. ... The list(range(5)) simulates the list [0, 1, 2, 3, 4]. With that, you need to iterate over every key in the dictionary, which can be accomplished as such: ... Save this answer. ... Show activity on this post. This checks if value of key in a dict is a superset of {2,3}:
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 18642171 โ€บ how-to-check-values-in-dictionary-with-multiple-data
python - How to check values in dictionary with multiple data - Stack Overflow
May 23, 2017 - I want to check the value of "u'first_name'" is C. but i want to make sure it is for the { u'first_name': u'c', u'last_name': u'cd',} user ... If I understand correctly, you are wanting to check if certain a last name has been updated to the correct first name. Since the order is unknown, and first names may be changed, it must also be necessary that last names are unique. If you must use a list of dictionaries for this you will need to loop through: