You’ll be able to
- Choose between mutable lists, immutable tuples, and unique sets
- Unpack tuples into multiple variables in one line
- Perform set operations: union, intersection, difference
- Convert between list, tuple, and set as needed
Loading lesson…
Why this matters
Tuples are the default return type for multi-value functions (divmod, os.path.split) and the only hashable sequence, making them dict-key material. Sets solve dedup and membership tests in O(1), a favorite interview trick.
Common pitfalls
- Writing
t = (1)for a single-item tuple. That is anint; the correct form ist = (1,)with a trailing comma. - Trying to mutate a tuple:
t[0] = 5raisesTypeError. Convert withlist(t)if you need mutation. - Assuming sets preserve order. They do not; use
dict.fromkeys(lst)if you need order-preserving dedup.