Tuples and Sets
LockedLesson 8 of 60 · DataStructures · Medium
Finish these first:Lists →Or pass the tests below to unlock it now.
The big idea
Tuples are immutable sequences (hashable if their items are). Sets store unique hashable items with O(1) membership.
Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Read the lesson
Tuples are immutable sequences (hashable if their items are). Sets store unique hashable items with O(1) membership.
point = (3, 4)
x, y = point # unpacking
s = {1, 2, 2, 3} # {1, 2, 3}
s | {4}; s & {2, 3}; s - {1}
Quick check
Before writing code: What should `unique_sorted([3,1,3,2])` return when your implementation of Tuples and Sets is working?
Your challenge
Write unique_sorted(xs) returning a sorted list of the distinct items.
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to java.collections-list-set (70% overlap). Python `set` ~ `HashSet<T>`; Java has no built-in tuple (use records).
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Tuples and Sets.
Learn this first
- ListsNot yet
Opens up next
This is the last lesson in this branch.