iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use a scan of data.items() to find a dictionary key by its value. A list comprehension returns every matching key; use next() when you need only the first match. Both scan the dictionary, so a reverse index is useful mainly when you will repeat lookups and the values are hashable.
Find every key that matches a value
Dictionary values do not have a built-in reverse lookup. Iterate through the key-value pairs with items() and compare each value with the target:
matches = [key for key, value in data.items() if value == target]
matches is a list of all keys whose values compare equal to target. If multiple keys have the same value, each matching key appears in the list. An empty list means there was no match.
Recommended Free Tools
This also works when values are unhashable, such as lists or dictionaries, because the scan compares values rather than using them as dictionary keys. The comparison is equality across the complete value; if you want to match one field inside a structured value, change the condition accordingly.
#1 Best Overall
Return only the first matching key
When one result is enough, use a generator with next():
key = next((key for key, value in data.items() if value == target), None)
This returns the first matching key in dictionary iteration order, or None if nothing matches. If None could itself be a valid matching key, use a unique sentinel so you can distinguish a missing match from that key:
Rank #2
missing = object()
key = next((key for key, value in data.items() if value == target), missing)
if key is missing:
print("No match")
else:
print(key)
For Python 3.7 and later, dictionary insertion order is guaranteed. Thus “first” means the earliest matching entry in iteration order. Updating the value of an existing key does not move its position; deleting and reinserting a key places it at the end. See the Python language reference.
Use an explicit loop for custom handling
A loop is clearer when you want to print matches, stop under additional conditions, or perform another action as soon as a match is found:
for key, value in data.items():
if value == target:
print(key)
This prints every matching key. To stop at the first one, add break after handling the match, or use the next() pattern above. The official Python data structures tutorial demonstrates iterating over dictionary key-value pairs with items().
Build a reverse index for repeated lookups
If you will search the same, mostly unchanged dictionary many times, build a dictionary that maps each value back to a key:
value_to_key = {value: key for key, value in data.items()}
key = value_to_key.get(target)
This is appropriate only when values can be dictionary keys—that is, they are hashable—and each value identifies one key. If values repeat, later entries overwrite earlier ones in the reverse dictionary, so it cannot return every original key. If duplicates matter, make each reverse entry a list instead:
Free tools Windows power users keep installed
One-click scans. No signup required.
from collections import defaultdict
value_to_keys = defaultdict(list)
for key, value in data.items():
value_to_keys[value].append(key)
matching_keys = value_to_keys.get(target, [])
A reverse index must also be kept in sync if the original dictionary changes. Rebuilding it or updating it alongside every change avoids searching stale mappings. For occasional searches, or whenever values may be unhashable, scan items() instead.
Best Value
Choose the lookup that fits
- Need every match: use the list comprehension; duplicate values remain represented by their separate keys.
- Need one match: use
next()with a default, choosing a sentinel ifNonecould be a key. - Need repeated lookups: consider a reverse index if values are hashable and you can account for duplicates and updates.
- Need custom behavior: use an explicit loop over
data.items().
For details on dictionary iteration and missing-key behavior, consult the official Python tutorial; for hashability and insertion-order guarantees, see the language reference.
Quick Recap
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.

