Python · Level 1 Advanced

Dicts, Sets & Tuples

Leverage Python's hash maps, unique sets, and immutable tuples for efficient, expressive algorithms.

  • dict creation & .get()/.items()
  • Set operations: union, intersection
  • Tuple unpacking

Dicts store key→value pairs for fast lookup. Sets hold unique items. Tuples are immutable ordered sequences.

# Dict - key/value lookup
scores = {"Alice": 95, "Bob": 87}
scores["Carol"] = 91
scores.get("Dave", 0)  # -> 0 (safe default)

# Set - unique items
tags = {"py", "web", "py"}  # -> {"py", "web"}

# Tuple unpacking
point = (10, 20)
x, y = point           # x=10, y=20

Write count_words(sentence) that returns a dict mapping each lowercased word to its frequency count.

solution.py
Test Suites Pending
Stdout