Interview Questions from "Fluent Python" Chapter 2: Sequences
Easy Questions
What are the two main categories of sequences based on mutability?
How do container sequences differ from flat sequences?
What is the key advantage of list comprehensions over
map/filter?How do you prevent list comprehensions from leaking variables (Python 2 vs. Python 3)?
What is the purpose of
collections.namedtuple?How does tuple unpacking work in Python?
What does the
*operator do in tuple unpacking (e.g.,a, *rest = [1, 2, 3])?Why do Python slices exclude the last item (e.g.,
my_list[0:3])?How do you reverse a sequence using slicing?
What is the difference between
list.sort()andsorted()?
Medium Questions
Explain how generator expressions save memory compared to list comprehensions.
How would you use a list comprehension to generate a Cartesian product?
When should you use
bisectinstead of theinoperator for membership tests?How does
bisect.insortmaintain a sorted sequence efficiently?Why might
array.arraybe preferable tolistfor numerical data?What is the purpose of
memoryviewin handling large datasets?How does
deque.rotate()work, and when would you use it?What happens when you assign to a slice (e.g.,
my_list[2:5] = [20, 30])?Why does
my_list = [[]] * 3create a list with shared references?How does the
keyparameter insorted()enable case-insensitive sorting?
Complex Questions
Explain the behavior of
a += bfor mutable vs. immutable sequences.Why does
t[2] += [50, 60]raise aTypeErrorbut still modify a tuple’s mutable element?How does NumPy’s
ndarrayimprove performance for numerical operations?Discuss the performance trade-offs of using
dequevs.listfor FIFO/LIFO operations.How can
memoryview.cast()manipulate binary data without copying bytes?When would you use
array.tofile()instead ofpicklefor saving numerical data?Explain how the
keyparameter in sorting functions leverages stability (e.g., Timsort).How does
bisectsupport efficient table lookups (e.g., converting scores to grades)?Why is
dequethread-safe for append/pop operations?Compare the performance of
array.fromfile()vs. reading floats from a text file.
These questions cover core sequence operations, performance optimizations, and practical applications from the chapter, suitable for evaluating a candidate's depth of understanding.

