Count unique elements in collection Dry Run in PYTHON

Count unique elements in collection 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.

Count unique elements in collection Program Code

# Count unique elements in various collections
# List
list_data = [1, 2, 2, 3, 3, 3, 4, 5, 5]
unique_count = len(set(list_data))
print(f"List: {list_data}")
print(f"Unique elements: {unique_count}")

# Tuple
tuple_data = (1, 1, 2, 2, 3, 4, 4, 5)
print(f"\nTuple: {tuple_data}")
print(f"Unique elements: {len(set(tuple_data))}")

# String
string_data = "programming"
print(f"\nString: '{string_data}'")
print(f"Unique characters: {len(set(string_data))}")

# Mixed data
mixed = [1, 'a', 2, 'a', 1, 'b', 3]
print(f"\nMixed: {mixed}")
print(f"Unique elements: {len(set(mixed))}")

View the complete Sets programs page.

Program Console Count unique elements in collection Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.