Thursday, June 19, 2025

Interview Questions on "Arrays" - Ch 2 - Fluent Python

All Posts on Python

Interview Questions from "Fluent Python" Chapter 2: Sequences

Easy Questions

  1. What are the two main categories of sequences based on mutability?

  2. How do container sequences differ from flat sequences?

  3. What is the key advantage of list comprehensions over map/filter?

  4. How do you prevent list comprehensions from leaking variables (Python 2 vs. Python 3)?

  5. What is the purpose of collections.namedtuple?

  6. How does tuple unpacking work in Python?

  7. What does the * operator do in tuple unpacking (e.g., a, *rest = [1, 2, 3])?

  8. Why do Python slices exclude the last item (e.g., my_list[0:3])?

  9. How do you reverse a sequence using slicing?

  10. What is the difference between list.sort() and sorted()?


Medium Questions

  1. Explain how generator expressions save memory compared to list comprehensions.

  2. How would you use a list comprehension to generate a Cartesian product?

  3. When should you use bisect instead of the in operator for membership tests?

  4. How does bisect.insort maintain a sorted sequence efficiently?

  5. Why might array.array be preferable to list for numerical data?

  6. What is the purpose of memoryview in handling large datasets?

  7. How does deque.rotate() work, and when would you use it?

  8. What happens when you assign to a slice (e.g., my_list[2:5] = [20, 30])?

  9. Why does my_list = [[]] * 3 create a list with shared references?

  10. How does the key parameter in sorted() enable case-insensitive sorting?


Complex Questions

  1. Explain the behavior of a += b for mutable vs. immutable sequences.

  2. Why does t[2] += [50, 60] raise a TypeError but still modify a tuple’s mutable element?

  3. How does NumPy’s ndarray improve performance for numerical operations?

  4. Discuss the performance trade-offs of using deque vs. list for FIFO/LIFO operations.

  5. How can memoryview.cast() manipulate binary data without copying bytes?

  6. When would you use array.tofile() instead of pickle for saving numerical data?

  7. Explain how the key parameter in sorting functions leverages stability (e.g., Timsort).

  8. How does bisect support efficient table lookups (e.g., converting scores to grades)?

  9. Why is deque thread-safe for append/pop operations?

  10. 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.

No comments:

Post a Comment