Comparison

Python List vs Tuple vs Set: Differences, Uses, Performance

Compare Python list, tuple, and set: mutability, ordering, duplicates, hashability, and Big-O performance with code examples and when to use each.

Python List vs Tuple vs Set: A Complete Comparison

Python's three most-used built-in collections look similar at a glance but behave very differently under the hood. Choosing the right one affects mutability, memory, ordering guarantees, and the Big-O cost of your hottest operations. This guide breaks down list, tuple, and set so you know exactly which to reach for.

Quick Comparison Table

Featurelisttupleset
Syntax[1, 2, 3](1, 2, 3){1, 2, 3}
OrderedYes (insertion)Yes (insertion)No
MutableYesNoYes
Allows duplicatesYesYesNo
IndexableYes lst[0]Yes t[0]No
HashableNoYes (if elements are)No
Usable as dict keyNoYesNo
Membership testO(n)O(n)O(1) avg
Append / addO(1) amortizedN/A (immutable)O(1) avg
Memory overheadHigherLowestHighest

list: The Ordered, Mutable Workhorse

Use a list when you need an ordered, growable sequence that may contain duplicates. Lists are backed by a dynamic array, so append is amortized O(1) and indexing is O(1), but x in lst and lst.remove(x) are O(n).

tasks = ["write", "review", "deploy"]
tasks.append("monitor")       # O(1) amortized
tasks[0] = "draft"             # mutable
"review" in tasks              # O(n) linear scan

tuple: The Immutable, Hashable Record

Tuples are fixed-size sequences. Because they cannot be modified after creation, Python can store them more compactly than lists and they become hashable as long as every element is hashable, which lets them serve as dictionary keys or set members.

point = (3, 4)
# point[0] = 9  -> TypeError: 'tuple' object does not support item assignment

distances = {(0, 0): 0, (3, 4): 5}   # tuple as dict key
seen_points = {(0, 0), (3, 4)}       # tuple inside a set

Tuples also shine as lightweight records or as multi-return values:

def min_max(nums):
    return min(nums), max(nums)     # returns a tuple

lo, hi = min_max([4, 1, 9, 2])       # tuple unpacking

set: Unordered Uniqueness with O(1) Lookups

Sets are hash tables. They store no duplicates, provide no positional index, and give you O(1) average-case membership tests plus fast union, intersection, and difference operations.

emails = {"[email protected]", "[email protected]", "[email protected]"}
# -> {"[email protected]", "[email protected]"}

"[email protected]" in emails       # O(1) average
emails.add("[email protected]")     # O(1) average

active = {"alice", "bob", "carol"}
banned = {"bob", "dave"}
active - banned           # {'alice', 'carol'}
active & banned           # {'bob'}

Because sets are unordered, you cannot say s[0]. You also cannot put a list or another set inside a set (both are unhashable), but you can insert tuples or frozensets.

frozenset: The Immutable Set

A frozenset is to set what tuple is to list: same lookup semantics, but immutable and therefore hashable. Reach for it when you need a set as a dictionary key, as an element of another set, or as a safe module-level constant.

ADMIN_ROLES = frozenset({"owner", "admin", "root"})
permissions = {frozenset({"read"}): "viewer",
               frozenset({"read", "write"}): "editor"}

Performance Implications

  • Membership checks in a hot loop: converting a list to a set turns an O(n*m) filter into O(n). For 100k items this is often a often 100x-1000x speedup depending on workload (converting a list to a set turns an O(n·m) filter into O(m)).
  • Iteration order: lists and tuples preserve insertion order; sets do not guarantee any specific order (CPython uses hash order, which changes between runs when hash randomization is enabled).
  • Memory: a tuple of ten ints is a bit smaller (roughly 120 vs 136 bytes in CPython for a 10-int container, with the gap growing as lists over-allocate) than the equivalent list, and a set is the largest of the three because of its hash-table load factor.
  • Construction cost: tuple literals are compiled as constants when possible, making them essentially free at runtime compared to list literals.

When to Use Which

  • Use a list when order matters, you need to append or mutate, and duplicates are meaningful (queues, task lists, streaming buffers).
  • Use a tuple for fixed records, function return values, dictionary keys, and any collection you want to guarantee stays constant.
  • Use a set for uniqueness, fast membership tests, and mathematical operations like union or difference on unordered collections.
  • Use a frozenset when you need set semantics but immutability — constants, cache keys, nested set elements.

Rule of Thumb

Ask two questions: Do I need to change it? If no, prefer a tuple or frozenset. Do I need fast in checks or uniqueness? If yes, prefer a set. Everything else defaults to a list.

python list vs tuple python set vs list tuple immutable frozenset python collections hashable types python big o when to use tuple

Explore 300+ Free Tools

Utilko has tools for developers, writers, designers, students, and everyday users — all free, all browser-based.