Skip to content
UniCircle
EasyConceptualBuilt-in data structures

list vs tuple vs set vs dict: which one and why?

Question PY-DAT-001

Compare Python's four main built-in collections. Give the typical time cost of a membership test (x in c) for each, and a situation where each is the right choice.

Show the explanation
listtuplesetdict
Syntax[1, 2](1, 2){1, 2} (empty: set()){"a": 1} (empty: {})
Ordered?yesyesnokeeps insertion order (guaranteed since 3.7)
Mutable?yesnoyesyes
Duplicates?allowedallowednokeys unique
x in cO(n) scanO(n) scanO(1) average (hash)O(1) average, on keys
Hashable (usable as a dict key)?noyes, if all its items areno (frozenset is)no

When to use which

  • list: an ordered sequence you will append to, sort or index: marks in exam order, a queue of tasks. (For a real queue, collections.deque gives O(1) pops from the left.)
  • tuple: a fixed record of a few related values, such as (lat, lng) or (roll, name), returning several values from a function, or a dict key made of several parts, as in seat[(row, col)].
  • set: fast membership tests and removing duplicates: seen = set(), banned_words, and set algebra with &, |, -.
  • dict: look a value up by a key: roll number to student, word to count.

Common follow-ups

  • {} is an empty dict, not a set.
  • A one-element tuple needs a comma: (5,). (5) is just the number 5.
  • A tuple is immutable, but if it holds a list, that list can still change: t = ([1],); t[0].append(2) works.
  • Sets and dicts need hashable elements or keys. That is why a list cannot be a key.

Original UniCircle question. Last reviewed 22 Oct 2026.