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
Last updated: 24 September 2026
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
| list | tuple | set | dict | |
|---|---|---|---|---|
| Written as | [1, 2] | (1, 2) | {1, 2} | {"a": 1} |
| Ordered | Yes | Yes | No | Yes, insertion order |
| Duplicates | Allowed | Allowed | Removed | Keys unique |
| Mutable | Yes | No | Yes | Yes |
| Can be a dict key or set member | No | Yes, if its items are hashable | No (use frozenset) | No |
| Access by | Position | Position | Membership only | Key |
| Typical use | A sequence you build and loop over | A fixed record | Unique 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
visits = ["pricing", "home", "pricing", "blog"]
print(visits)
print(tuple(visits))
print(sorted(set(visits)))
print(dict.fromkeys(visits))['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):
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)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:
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")list: 396 microseconds per check, set: 36 nanoseconds per checkThese 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
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}))88 64 216 224These 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 inyesterday_users - today_usersto find who did not come back. - dict:
getwith a default,setdefault,items()for key and value together, and view objects such askeys()that support set operations:a.keys() & b.keys()finds keys the two dictionaries share.
Choosing: four questions
- Do you look things up by something other than position? Use a dict, keyed by that thing.
- Do you only need unique values, or fast "have I seen this?" checks? Use a set.
- Is it a fixed group of values that belong together, or a key made of several parts? Use a tuple.
- 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?
Can a dictionary have duplicate values?
Why does my set print in a different order each time?
How do I make a list of unique items without losing the 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
- Data Structures (tutorial) β Python documentation
- Mapping types: dict β Python documentation
- Glossary: hashable β Python documentation
- sys.getsizeof β Python documentation
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.
Related articles
Learn Python from Scratch: A Complete 2026 Roadmap
How to learn Python from zero: install a current version (including the new Windows install manager), then work through seven stages, from values and loops to files, virtual environments, classes and tests, each ending with a small program you should be able to write on your own.
Python Interview Questions: Top 50 with Answers
Fifty conceptual Python interview questions with short, precise answers, grouped by topic: basics, types and mutability, data structures, functions and scope, OOP, iterators and decorators, errors and files, and internals, with runnable examples for the ones people most often get wrong.
Python for Data Science: The Essential Libraries
The Python data science stack explained by the job each library does: NumPy for arrays, pandas for tables, Matplotlib and seaborn for charts, SciPy and statsmodels for statistics, scikit-learn for models and Jupyter for exploration, with one runnable example that passes a real dataset through them.