What are the differences between lists, tuples, sets, and dictionaries in Python?
Updated Feb 20, 2026
Short answer
Python collections differ by behavior: lists are ordered and mutable, tuples are ordered and immutable, sets store unique values, and dictionaries store key-value mappings. The right choice depends on whether you need changing data, fixed data, uniqueness, or fast lookup.
Deep explanation
Python provides four commonly used built-in collection types, each designed for a different way of organizing data. An interviewer wants to hear that you understand the trade-offs, not just how to create each type.
Choose the collection based on how you access and modify the data, not just on what syntax looks shortest.
Quick comparison
| Type | Ordered | Mutable | Main purpose |
|---|---|---|---|
list | Yes | Yes | Store items in sequence |
tuple | Yes | No | Store fixed groups of values |
set | No meaningful index order | Yes | Store unique values |
dict | Yes (insertion order) | Yes | Store key-value relationships |
Python dictionaries preserve insertion order in modern Python versions, but they are still accessed by keys rather than numeric positions. ([Python documentation][1])
Lists: ordered and changeable
A list is the most flexible general-purpose collection. It stores items in a sequence, allows duplicates, and lets you change its contents after creation.
Examples of list operations:
append()adds an itemremove()deletes an itemsort()rearranges itemslist[index]accesses a position
Lists are a good choice when you care about order and expect the data to change.
items = ["apple", "bread", "milk"]
items.append("eggs")items[0] = "banana"
print(items)Tuples: ordered but immutable
A tuple behaves like a list that cannot be changed after it is created. This makes tuples useful for values that represent a single fixed record.
For example, a point on a map can be represented as a tuple:
location = (28.6139, 77.2090)Because tuples are immutable, they can be safer when data should not accidentally be modified.
Sets: unique collections
A set stores unique values and is optimized for membership testing. If you add the same value multiple times, the set keeps only one copy.
Common uses:
- Removing duplicates
- Checking whether something exists
- Performing operations like union and intersection
For example, checking whether a username has already been used is often a good set operation.
Dictionaries: key-value storage
A dictionary stores relationships between keys and values. Instead of finding data by position, you retrieve it using a key.
A dictionary is useful when you need to answer questions like:
- "What is the user's email?"
- "What is the product price?"
- "What is this item's configuration?"
The relationship looks like this:
A simple way to remember the differences:
⚠️ Lists answer "what is the item at this position?", while dictionaries answer "what value belongs to this key?"
Choosing between them
Use a list when:
- Order matters
- Duplicate values are allowed
- You need to modify elements
Use a tuple when:
- The values should stay constant
- The data represents one fixed group
Use a set when:
- Uniqueness matters
- You need fast membership checks
Use a dict when:
- You need to associate one piece of information with another
The biggest interview distinction is mutable vs immutable: lists, sets, and dictionaries can change; tuples cannot.
Real-world example
Imagine building an online store.
- A
listcan hold products shown on a page because the display order matters. - A
setcan track product categories without duplicates. - A
tuplecan store a fixed product dimension like(width, height, depth). - A
dictcan store product details by ID.
products = ["Laptop", "Phone", "Tablet"]
categories = {"Electronics", "Accessories"}
dimensions = (30, 20, 2)
product = { "id": 101, "name": "Laptop", "price": 999}
print(product["name"])The application chooses each structure based on the operation it performs most often.
Common mistakes
- * **Confusing order** - Assuming sets have reliable positions
- use a list if you need indexing.
- * **Changing tuples** - Trying to update tuple values
- create a new tuple instead.
- * **Using lists for lookups** - Searching large lists repeatedly can be slower
- use a dictionary or set when appropriate.
- * **Forgetting duplicate behavior** - Sets remove duplicates automatically, while lists keep them.
- * **Using mutable keys** - Dictionary keys must be hashable
- use immutable values such as strings or tuples.
Follow-up questions
- Why are tuples immutable in Python?
- What is the difference between a set and a dictionary?
- When would you choose a list over a set?
- Are dictionaries ordered in Python?