Choosing the right built-in data structure is one of the clearest Python interview signals. The interviewer is listening for more than syntax. They want to know whether you can match order, mutation, uniqueness and lookup cost to the problem.
The four core choices overlap, but they do not have the same contract. Start from the operation you will perform most often.
Lists: ordered and mutable
A list is an ordered, mutable sequence. It permits duplicates and supports index access, so it is a natural fit for a sequence that changes over time.
scores = [72, 81, 72]
scores.append(90)
scores[0] = 75Indexing and assigning at a known index are O(1). Appending is amortized O(1): an occasional resize costs O(n), but that cost is spread over many inexpensive appends. Inserting or deleting near the front is O(n) because later references shift. Testing x in scores is O(n) because the list may need a linear scan.
A list is wrong when the main requirement is frequent membership testing over many elements. It is also a poor queue if you repeatedly call pop(0), which shifts the remaining elements. Use a set for membership or a deque for efficient operations at both ends.
Lists are unhashable because their contents can change. You cannot use a list as a dictionary key or as an element of a set.
Tuples: fixed sequence records
A tuple is an ordered sequence whose positions cannot be reassigned after creation. Indexing is O(1), while membership is O(n), just as for a list.
Tuples work well for fixed records and multiple return values:
point = (4, 7)
x, y = point
name, *marks = ("Asha", 78, 84, 91)The first assignment unpacks two positions. The starred target in the second collects the remaining values into the list [78, 84, 91].
Immutability does not automatically make every tuple hashable. A tuple is hashable only if every element it holds is itself hashable. (4, 7) can be a dictionary key, but ([4], 7) cannot because it contains a list.
A tuple may also reference a mutable object. You cannot replace a tuple slot, but a list stored in that slot can still be changed. Say “the tuple's references are fixed,” not “everything reachable from a tuple is frozen.”
Sets: fast membership and algebra
A set is a mutable collection of unique, hashable elements. It does not promise positional order, so there is no s[0]. Its main advantage is average O(1) membership, insertion and deletion through hashing.
Deduplication is concise:
unique_ids = set([7, 3, 7, 5, 3])The result contains 3, 5 and 7, but code should not depend on the order in which a set prints them.
Set algebra turns common loops into direct operations. Let:
a = {1, 2, 3, 4}
b = {3, 4, 5}Then:
Union,
a | b, is{1, 2, 3, 4, 5}.Intersection,
a & b, is{3, 4}.Difference,
a - b, is{1, 2}.Symmetric difference,
a ^ b, is{1, 2, 5}.
Check the symmetric difference another way: the union has five elements, and removing the two common elements 3 and 4 leaves 1, 2 and 5.
The operation cost depends on the input sizes and hash behaviour, but membership in one ordinary set is expected O(1). Use a frozenset when you need an immutable, hashable set value.
Dictionaries: key-value lookup
A dictionary maps unique, hashable keys to values. Average lookup, insertion and deletion by key are O(1). Values may repeat and may be mutable; the hashability restriction applies to keys.
Since Python 3.7, dictionaries preserve insertion order as a language guarantee. That does not mean they sort keys. Updating an existing key changes its value without moving it to a newly sorted position.
A dictionary comprehension builds a mapping directly. This one keeps even inputs from 1 through 4 and maps each to its square:
squares = {n: n * n for n in range(1, 5) if n % 2 == 0}
print(squares)Running it prints:
{2: 4, 4: 16}Trace it to verify: 2 % 2 = 0, so 2: 2 * 2 = 4 is included. 4 % 2 = 0, so 4: 4 * 4 = 16 is included. Inputs 1 and 3 fail the condition.
Use d.get(key, default) when a missing key has a sensible fallback. Use key in d for membership because it checks keys directly and is clearer than searching d.keys().
Decision table for Python containers
Structure | Ordered? | Mutable? | Hashable itself? | Cost of | Best signal |
|---|---|---|---|---|---|
list | yes | yes | no | O(n) | changing sequence |
tuple | yes | no | if every element is hashable | O(n) | fixed record or hashable sequence |
set | no positional order | yes | no | average O(1) | uniqueness and membership |
dictionary | insertion ordered | yes | no | average O(1) for keys | key-value lookup |

Those average costs assume ordinary, well-distributed hashes. Collisions and adversarial inputs can degrade hash-table performance, which is why set and dictionary lookup is quoted as expected or average time rather than a worst-case guarantee.
Six common interview questions
These six phrasings come up in almost every fresher round. Answer each one as a rule followed by its consequence for your code, rather than a definition on its own. The wider set, including output-prediction and copy-semantics questions, sits in Python Interview Questions for Freshers 2026.
1. List or tuple?
Use a list when the sequence must change. Use a tuple for a fixed record, especially when a hashable sequence key is useful.
2. Why is set membership faster than list membership?
A set uses a hash table to locate a likely slot in expected O(1). A list checks elements sequentially in O(n).
3. Can a tuple contain a list?
Yes, but that tuple is not hashable. The list may still mutate even though the tuple slot cannot be rebound.
4. Are dictionaries sorted?
No. Since Python 3.7 they preserve insertion order, which is different from sorting by key.
5. How do you remove duplicates while keeping first-seen order?
For hashable values, list(dict.fromkeys(items)) uses dictionary key uniqueness and insertion order.
6. What can be a dictionary key?
A key must be hashable, with a stable hash and equality behaviour during its use. Numbers, strings and suitable tuples are common examples.
The short version
Use a list for a changing sequence, a tuple for a fixed sequence record, a set for uniqueness and fast membership, and a dictionary for key-value lookup. State the dominant operation and its expected cost when explaining your choice.
KnowledgeGate has about 480 Python practice questions. Build the concepts through the Python programming course, then test structure choice through Data Structures MCQs. The Coding and CS fundamentals guide supplies the wider interview context.
Use the CS Fundamentals category as the next-step map. For every problem, ask four questions: must order be retained, can values change, must duplicates disappear, and how often will membership be tested?




