Answer guide
Read the answer guide
Choose a tuple for a small fixed record whose shape does not change, such as a coordinate pair or a row returned from a query, and a list for a collection that grows, shrinks or is reordered. Tuples signal intent to readers and can be used as dictionary keys when everything inside is hashable. Be careful: a tuple only fixes which objects it holds, so a list stored inside can still be modified. A simple rule is that position carries meaning for tuples and repetition carries meaning for lists.
What the interviewer is assessing
Whether you can pick a data structure by intent and understand what immutability does and does not guarantee.
Common mistakes
- Says tuples are just faster lists and ignores the meaning they convey.
- Claims everything inside a tuple is frozen, forgetting a contained list can change.
Practise a follow-up
- Can a tuple containing a list be a dictionary key?
- When would a named tuple or dataclass be clearer than a plain tuple?