Unit: Unit 5: Dictionaries and Sets • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Create sets and eliminate duplicates from a list
primary_colors = {"red", "green", "blue"}
# Duplicate items are automatically deduplicated
numbers = {1, 2, 2, 3, 3, 3, 4}
# Creating an empty set (MUST use set(), not {})
empty_set = set()
# Deduplicating a list of tags
raw_tags = ["python", "ai", "web", "python", "ai", "data"]
unique_tags = sorted(list(set(raw_tags)))
print("Primary colors sorted:", sorted(primary_colors))
print("Numbers deduplicated:", sorted(numbers))
print("Type of empty_set:", type(empty_set).__name__)
print("Unique tags list:", unique_tags)