10.18 Interview Questions
Frequently asked and scenario-based Python list interview questions covering list vs tuple, append() vs insert(), sort() vs sorted(), shallow vs deep copy, and classic coding problems like safe iteration and binary search.
Conceptual Questions
- What’s the difference between a list and a tuple?
- Why is
list.append()O(1) amortized butlist.insert(0, x)O(n)? - What’s the difference between
sort()andsorted()? - What’s the difference between a shallow copy and a deep copy of a list?
- Why shouldn’t a mutable object be used as a function’s default argument value?
Scenario-Based Questions
- Every even number needs to be removed from a list while iterating — what’s the safe way to do it, and why does the naive approach fail?
- A function receives a list and appends to it — does the caller see the change? What if it received an
intinstead? - A large list needs fast, repeated membership checks — what would change, and why?
Coding Questions
- Write a function to remove duplicates from a list while preserving order.
- Implement binary search on a sorted list without using any built-in search function.
- Given a list of dicts (like instance records), write a comprehension that extracts IDs matching a condition.
def remove_duplicates(l):
return list(dict.fromkeys(l))
>>> remove_duplicates([3, 1, 3, 2, 1])
[3, 1, 2]
Quick Interview Answer
“List interview questions cluster around three things: confirming mutability and reference-sharing are understood (list vs. tuple, shallow vs. deep copy, the mutable-default-argument trap), knowing the time complexity trade-offs that drive real design decisions (
appendvs.insert(0, ...), list membership vs. aset), and classic coding problems — safe removal during iteration, order-preserving deduplication, binary search — that test comfort with slicing,dict.fromkeys(), and index arithmetic rather than memorized syntax.”
Common Mistakes
- Answering “a list and a tuple are basically the same, just different brackets” without mentioning mutability, hashability, or the performance/memory implications.
- Solving the “remove while iterating” scenario by suggesting a
whileloop with manual index tracking instead of the simpler iterate-over-a-copy pattern. - Forgetting binary search’s precondition — the list must already be sorted — and describing it as a general-purpose search technique.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form