Find duplicate values in dictionary Dry Run in PYTHON

Find duplicate values in dictionary is an interactive PYTHON dry run visualizer from the Dict programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Find duplicate values in dictionary Program Code

# Find duplicate values in dictionary
data = {"task1": "done", "task2": "pending", "task3": "done", "task4": "progress", "task5": "pending"}
print("Original:", data)

# Method 1: Using dictionary to count frequencies
value_count = {}
for value in data.values():
    value_count[value] = value_count.get(value, 0) + 1

duplicate_values = {val: count for val, count in value_count.items() if count > 1}
print("Duplicate values and their counts:", duplicate_values)

# Method 2: Find which keys have duplicate values
from collections import defaultdict
value_to_keys = defaultdict(list)
for key, value in data.items():
    value_to_keys[value].append(key)

duplicate_info = {val: keys for val, keys in value_to_keys.items() if len(keys) > 1}
print("\nKeys with duplicate values:")
for val, keys in duplicate_info.items():
    print(f"  Value {val} appears for keys: {keys}")

# Method 3: List of duplicate values only
dups = [val for val, count in value_count.items() if count > 1]
print(f"\nDuplicate values list: {dups}")

View the complete Dict programs page.

Program Console Find duplicate values in dictionary Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.