Find common elements between two sets Dry Run in PYTHON

Find common elements between two sets is an interactive PYTHON dry run visualizer from the Sets 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 common elements between two sets Program Code

# Find common elements between two sets
set_a = {1, 2, 3, 4, 5, 6, 7}
set_b = {5, 6, 7, 8, 9, 10}

print("Set A:", set_a)
print("Set B:", set_b)

# Method 1: Using intersection operator &
common = set_a & set_b
print(f"\nCommon elements (&): {common}")

# Method 2: Using intersection() method
common2 = set_a.intersection(set_b)
print(f"Using intersection(): {common2}")

# Method 3: Manual loop
common3 = set()
for item in set_a:
    if item in set_b:
        common3.add(item)
print(f"Manual loop: {common3}")

View the complete Sets programs page.

Program Console Find common elements between two sets Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.