33 lessons
Python · Module 3Module material

Data Structures interview questions

25 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.

Choosing a structure

  1. What is the difference between a list, a tuple, a set and a dictionary?●
  2. When would you choose a tuple over a list?●●
  3. Why is x in some_set faster than x in some_list?●●
  4. What does "hashable" mean, and which built-in types are hashable?●●

Lists

  1. What do week[-1], week[-3:] and week[::-1] give?●
  2. What happens when you index past the end of a list, and when you slice past it?●
  3. What is the difference between sort() and sorted()?●●
  4. What is aliasing? How do you copy a list?●●
  5. What is the difference between x = x + [4] and x += [4] for a list?●●
  6. What does [[0] * 3] * 3 build, and why is it a trap?●●
  7. Why should you not remove items from a list while looping over it?●●

Tuples

  1. How do you write a tuple with one item?●
  2. Can a tuple change?●●
  3. What is unpacking, and what happens when the counts do not match?●●

Sets

  1. How do you create an empty set?●
  2. What are union, intersection, difference and symmetric difference?●●
  3. What is the difference between a set's remove and discard?●●

Dictionaries

  1. What is the difference between d[key] and d.get(key)?●
  2. Are dictionaries ordered?●●
  3. How do you count items in Python?●●
  4. What is a defaultdict, and what is its trap?●●
  5. How do you loop over a dictionary's keys and values together?●●

Strings

  1. Strings are immutable. What does that mean for their methods?●●
  2. How do you check whether a string is a palindrome?●●

Comprehensions

  1. What is a list comprehension, and when should you not use one?●●

Directory listings

  • SchoolWhool on Siteefy