Tuples & Sets
beginner10 min readLesson 17 of 169
Fixed-shape tuples and uniqueness-driven sets โ when each wins.
Tuples and sets complete the container toolbox.
Tuple โ a list that never changes
point = (3, 4)
point[0] # 3
point[0] = 9 # TypeError!
Use tuples for fixed groups: coordinates, RGB colors, (day, month, year).
They signal intent: "this shape does not change". One element needs a comma:
(42,).
Set โ uniqueness, fast membership
tags = {"python", "coding", "python"}
len(tags) # 2 โ duplicates vanish
"python" in tags # very fast, even for huge sets
tags.add("learning")
Sets have no order and no duplicates โ perfect for "have I seen this?" checks
and deduplication: set(my_list) removes duplicates.
Choosing the container
| Need | Use | | --- | --- | | Ordered items, will change | list | | Fixed shape, never changes | tuple | | Uniqueness + fast lookup | set | | Key โ value lookups | dict (next lesson) |