GCGrowCarrer

Tuples and Sets

Locked

Lesson 8 of 60 · DataStructures · Medium

ListsNext: Dictionaries

Finish these first:Lists →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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}
3

Quick check

Before writing code: What should `unique_sorted([3,1,3,2])` return when your implementation of Tuples and Sets is working?

4

Your challenge

2 sample tests, 1 hidden

Write unique_sorted(xs) returning a sorted list of the distinct items.

Stuck? Get a hint (free)
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.

Mastery0%

Learn this first

Opens up next

This is the last lesson in this branch.