Menu

Python interview question · Question 2 of 4

List vs tuple vs set: when would you use each in a data pipeline?

  • Easy
  • conceptual
  • ~5 min
  • Foundational relevance
  • 2 min read
  • Updated Oct 2026

Short answer

Use a list for an ordered, changeable sequence such as records you append to. Use a tuple for a fixed record that should not change, and when you need a hashable value such as a composite dictionary key. Use a set when you need fast membership checks or deduplication, because lookups are O(1) on average, accepting that a set has no order and no duplicates.

On this page
  1. Detailed explanation
  2. Example in a pipeline
  3. Common mistakes

Detailed explanation

list tuple set
Ordered Yes Yes No
Mutable Yes No Yes
Duplicates Allowed Allowed Removed
Hashable No Yes, if its items are No (frozenset is)
x in ... O(n) O(n) O(1) average

Example in a pipeline

batch = []                                   # list: rows accumulate in order
batch.append(("2026-10-01", "north", 150))   # tuple: a fixed record
batch.append(("2026-10-01", "south", 230))

already_loaded = {("2026-10-01", "north")}   # set of tuple keys
to_load = [r for r in batch if (r[0], r[1]) not in already_loaded]
print(to_load)
[('2026-10-01', 'south', 230)]

Common mistakes

  1. Checking membership against a large list inside a loop.
  2. Expecting a set to preserve order.
  3. Thinking a tuple is “always hashable”: (1, [2]) is not, because it contains a list.

By Data Career Hub Editorial · Last reviewed Oct 2026 · Examples run on Python 3.12

Progress is saved in this browser only. No account needed.

Search
Filter by type