Python Lists vs Tuples vs Sets vs Dictionaries

Python's four core collections compared on the properties that decide which to use: order, duplicates, mutability, whether they can be dictionary keys, how fast membership tests are and how much memory they take, with runnable demonstrations and a short set of questions that picks the right one.

GloryTecks Team

Training & Placement Faculty

6 May 2026 6 min read

Last updated: 24 September 2026

Share:

Lists, tuples, sets and dictionaries are the four collections you use every day in Python. Beginners usually learn their syntax in an afternoon, then spend months reaching for a list by habit, even when a set or a dictionary would make the code shorter and faster. The choice comes down to a handful of properties, and each can be demonstrated in a line or two.

The four at a glance

listtuplesetdict
Written as[1, 2](1, 2){1, 2}{"a": 1}
OrderedYesYesNoYes, insertion order
DuplicatesAllowedAllowedRemovedKeys unique
MutableYesNoYesYes
Can be a dict key or set memberNoYes, if its items are hashableNo (use frozenset)No
Access byPositionPositionMembership onlyKey
Typical useA sequence you build and loop overA fixed recordUnique items, fast "is it in?"Look up a value by a key

The Python tutorial describes each of them in these terms (Python tutorial: data structures). The rest of this article shows why the rows matter.

Order and duplicates

python
visits = ["pricing", "home", "pricing", "blog"]
print(visits)
print(tuple(visits))
print(sorted(set(visits)))
print(dict.fromkeys(visits))
text
['pricing', 'home', 'pricing', 'blog']
('pricing', 'home', 'pricing', 'blog')
['blog', 'home', 'pricing']
{'pricing': None, 'home': None, 'blog': None}

Lists and tuples keep every item in order, including repeats. A set keeps each value once but has no order, so it is printed through sorted() here; printing a set directly can list items in any order. A dictionary keeps its keys unique and in insertion order, which makes list(dict.fromkeys(items)) the idiomatic way to remove duplicates while keeping the first occurrence of each (Python docs: dict).

Mutability and hashing

A tuple cannot be changed after it is created. That sounds like a restriction; in practice it is what makes tuples usable as dictionary keys and set members, which require a hash that never changes (Python glossary: hashable):

python
pin_by_city = {("Hyderabad", "Telangana"): "500001", ("Pune", "Maharashtra"): "411001"}
print(pin_by_city[("Pune", "Maharashtra")])

key = ("Hyderabad", "Telangana")
try:
    key[0] = "Secunderabad"                      # tuples cannot change
except TypeError as exc:
    print("TypeError -", exc)
try:
    {["Hyderabad", "Telangana"]: "500001"}       # lists cannot be keys
except TypeError as exc:
    print("TypeError -", exc)
text
411001
TypeError - 'tuple' object does not support item assignment
TypeError - unhashable type: 'list'

A list cannot be a key, because it could change after being stored and the dictionary would lose track of it. A tuple of immutable values can. Composite keys such as (city, state) or (year, month) are one of the best reasons to use tuples. The same rule applies to sets: a set of tuples works, a set of lists does not, and frozenset is the immutable, hashable version of a set.

Membership speed

Checking x in collection is where the choice matters most for performance. A list checks each element in turn; a set or dictionary hashes the value and jumps straight to where it would be:

python
import timeit

ids_list = list(range(100_000))
ids_set = set(ids_list)
per_list = min(timeit.repeat(lambda: 99_999 in ids_list, number=1000, repeat=3)) / 1000
per_set = min(timeit.repeat(lambda: 99_999 in ids_set, number=100_000, repeat=3)) / 100_000
print(f"list: {per_list * 1e6:.0f} microseconds per check, set: {per_set * 1e9:.0f} nanoseconds per check")
text
list: 396 microseconds per check, set: 36 nanoseconds per check

These timings come from one run and vary by machine, but the gap of several orders of magnitude does not. It grows with the size of the list, because the list check is O(n) and the set check is O(1) on average. The practical rule: if you test membership repeatedly, convert to a set once, then test against the set.

Memory

python
import sys

print(sys.getsizeof([1, 2, 3]), sys.getsizeof((1, 2, 3)), sys.getsizeof({1, 2, 3}), sys.getsizeof({1: None, 2: None, 3: None}))
text
88 64 216 224

These are the sizes in bytes of the containers themselves in 64-bit CPython 3.11, not the integers inside them (Python docs: sys.getsizeof). A tuple is the leanest because it never needs room to grow; a list reserves spare capacity for appends; sets and dictionaries use hash tables with empty slots so lookups stay fast. The differences rarely matter for a handful of objects, but for millions of small records, tuples (or namedtuple) are noticeably lighter than dictionaries. The trade-off is readability: a dictionary's keys document each field, which is why a namedtuple or a dataclass is usually the better compromise for records you pass around your code.

Useful operations each one is built for

  • list: append, insert, sort, slicing, and indexing by position. The natural result type of a comprehension.
  • tuple: unpacking into names, as in city, state = key, and returning several values from a function.
  • set: union |, intersection & and difference -, as in yesterday_users - today_users to find who did not come back.
  • dict: get with a default, setdefault, items() for key and value together, and view objects such as keys() that support set operations: a.keys() & b.keys() finds keys the two dictionaries share.

Choosing: four questions

  1. Do you look things up by something other than position? Use a dict, keyed by that thing.
  2. Do you only need unique values, or fast "have I seen this?" checks? Use a set.
  3. Is it a fixed group of values that belong together, or a key made of several parts? Use a tuple.
  4. Otherwise, for an ordered collection you add to and loop over, use a list.

When none of the four fits exactly, such as a queue, a counter or a priority list, the standard library has a specialised structure; the Python data structures reference covers deque, Counter, defaultdict, heapq and bisect.

Is a tuple faster than a list?

Creating and iterating a tuple is slightly faster and it uses less memory, but the difference is small. Choose a tuple for what it means, a fixed record, rather than for speed.

Can a dictionary have duplicate values?

Yes. Keys must be unique; values can repeat freely. If you need to look up by value as well, keep a second dictionary in the other direction.

Why does my set print in a different order each time?

Sets are unordered, and the order in which Python stores strings in a set can differ between runs because string hashing is randomised for security. Sort the set when you need a stable order.

How do I make a list of unique items without losing the order?

Use list(dict.fromkeys(items)). A set removes duplicates too, but it does not keep the original order.

All four are usually built with comprehensions, covered in the list comprehensions guide. Choosing the right one is a staple of coding interviews too; see the Python interview questions. Lists, tuples, sets and dictionaries are the core of the data structures module of the Python Programming course.

Sources

GloryTecks Team

Training & Placement Faculty

The GloryTecks faculty team mentors learners across Data Science, AI and Data Engineering, with a focus on real-time projects and placement readiness in Hyderabad.

Want to master Python?

Join GloryTecks’ expert-led Python Programming training in Hyderabad with real-time projects and 100% placement support.

Explore course