Reference library

Dictionaries & sets

Key–value maps, uniqueness, counting, grouping, and fast lookups.

1 match
Dictionaries & sets easy

How to Find Keys with Matching Values in Two Dictionaries in Python

Find dictionary keys where both dictionaries have the exact same value by iterating over key-value pairs and comparing them.

dictionaries comparison data-matching
Python
def find_matching_values(dict1, dict2):
    """Return list of keys that have the same value in both dicts."""
    matches = []
    for key, value in dict1.items():
        if key in dict2 and dict2[key] == value:
            matches.append(key)
    return matches


if __name__ == "__main__":
    # Example usage
    di…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Dictionaries & sets — Python code examples

What you will find here

This page collects dictionaries & sets snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.