List vs Tuple vs Set vs Dictionary in Python
In this lesson: Difference between list, tuple, set and dictionary in Python — mutability, order, duplicates — comparison table. In Hindi & English.
Four ways to store data
Python has four main built-in ways to store a collection of data: list, tuple, set and dictionary. They differ in whether they can change, whether they keep order, and whether they allow duplicates. Picking the right one makes your code cleaner and faster.
List
An ordered, changeable collection — the most common one.
fruits = ["apple", "mango", "banana"]
fruits.append("kiwi") # add
fruits[0] = "orange" # change
print(fruits)
Lists use square brackets [], keep their order, allow duplicates, and can be changed freely. Use them for data that grows or changes.
Tuple
An ordered collection that cannot be changed after creation.
point = (10, 20)
print(point[0]) # read is fine -> 10
# point[0] = 5 # ERROR: tuples are immutable
Tuples use round brackets (). They keep order and allow duplicates, but are fixed. Use them for data that should not change, like coordinates or settings.
Set
An unordered collection of only unique values.
nums = {1, 2, 2, 3, 3, 3}
print(nums) # duplicates dropped
nums.add(4)
print(4 in nums) # fast membership check
True
Sets use curly braces {} with just values. They drop duplicates automatically and are great for uniqueness and fast "is it in here?" checks — but they keep no order.
Dictionary
Stores key-value pairs, so you look up a value by its key.
student = {"name": "Aman", "marks": 88}
print(student["name"]) # Aman
student["class"] = 12 # add a pair
print(student)
{'name': 'Aman', 'marks': 88, 'class': 12}
Dictionaries use curly braces with key: value pairs. Use them when each value needs a meaningful label, like a record of fields.
Quick comparison
| Type | Brackets | Changeable? | Order? | Duplicates? |
|---|---|---|---|---|
| list | [ ] | Yes | Yes | Yes |
| tuple | ( ) | No | Yes | Yes |
| set | { } | Yes | No | No |
| dict | { key: val } | Yes | Yes | Keys unique |
Common mistakes
- Trying to change a tuple. Tuples are immutable — use a list if you need to edit.
- Relying on set order. Sets have no order; do not expect items in sequence.
- Using a list when you need uniqueness. A set removes duplicates for free.
- Confusing set and dict braces. Both use
{}; a dict haskey: value, a set has only values.
Summary
- List [ ] — ordered, changeable, allows duplicates.
- Tuple ( ) — ordered, fixed (immutable).
- Set { } — unordered, unique values only.
- Dict { key: value } — labelled key-value pairs.
- Choose by whether you need to change data, keep order, or ensure uniqueness.
Next, dive into list comprehension, or loop over any of these with Python loops.
Frequently Asked Questions
What is the main difference between a list and a tuple?
When should I use a set?
What is a dictionary used for?
Which ones keep their order?
Which brackets does each use?
[], tuple uses round brackets (), and both set and dict use curly braces {} — a set has just values, while a dict has key: value pairs.