Python
List vs Tuple vs Dictionary in Python — Difference, When to Use, Examples
List vs Tuple vs Dictionary in Python explained — mutability, ordering, performance, methods, and when to use each. Comparison table, code examples, and answers to common questions.
This is one of the most frequently asked questions in CBSE Class 11 and 12 Computer Science exams. Understanding the differences between List, Tuple, and Dictionary is essential for both theory and practical questions.
Quick Overview
- List - An ordered, mutable collection. Uses square brackets
[]. - Tuple - An ordered, immutable collection. Uses parentheses
(). - Dictionary - An unordered collection of key-value pairs. Uses curly braces
{}.
Complete Comparison Table
| Feature | List | Tuple | Dictionary |
|---|---|---|---|
| Syntax | [1, 2, 3] |
(1, 2, 3) |
{"a": 1, "b": 2} |
| Mutable | Yes | No | Yes |
| Ordered | Yes | Yes | Yes (Python 3.7+) |
| Duplicates | Allowed | Allowed | Keys must be unique |
| Indexing | Yes (a[0]) |
Yes (a[0]) |
By key (a["name"]) |
| Slicing | Yes | Yes | No |
| Brackets | Square [] |
Round () |
Curly {} |
| Empty creation | a = [] |
a = () |
a = {} |
| Speed | Slower | Faster | Fastest for lookup |
| Use case | Collection that changes | Fixed data | Key-value mapping |
| Nesting | Yes | Yes | Yes |
| Methods | Many (append, remove, etc.) | Few (count, index) | Many (keys, values, etc.) |
Creating Each Type
List
# Different ways to create a list
marks = [85, 92, 67, 78]
names = ["Aman", "Priya", "Rahul"]
mixed = [1, "hello", 3.14, True]
empty = []
Tuple
# Different ways to create a tuple
marks = (85, 92, 67, 78)
single = (5,) # Comma is required for single element
names = ("Aman", "Priya", "Rahul")
empty = ()
Important: A single-element tuple needs a trailing comma. Without it, Python treats it as a regular value in parentheses.
a = (5) # This is int, NOT a tuple
b = (5,) # This is a tuple
print(type(a)) # <class 'int'>
print(type(b)) # <class 'tuple'>
Dictionary
# Different ways to create a dictionary
student = {"name": "Aman", "marks": 85, "city": "Delhi"}
empty = {}
Accessing Elements
List, By Index
marks = [85, 92, 67, 78]
print(marks[0]) # 85
print(marks[-1]) # 78
print(marks[1:3]) # [92, 67]
Tuple, By Index
marks = (85, 92, 67, 78)
print(marks[0]) # 85
print(marks[-1]) # 78
print(marks[1:3]) # (92, 67)
Dictionary, By Key
student = {"name": "Aman", "marks": 85, "city": "Delhi"}
print(student["name"]) # Aman
print(student.get("marks")) # 85
print(student.get("age", 0)) # 0 (default if key not found)
Modifying Elements
List, Mutable (Can Change)
marks = [85, 92, 67, 78]
marks[0] = 90 # Change first element
marks.append(88) # Add at end
marks.insert(1, 75) # Insert at index 1
marks.remove(67) # Remove first occurrence of 67
marks.pop() # Remove and return last element
print(marks)
[90, 75, 92, 78]
Tuple, Immutable (Cannot Change)
marks = (85, 92, 67, 78)
# marks[0] = 90 # ERROR! TypeError: 'tuple' does not support item assignment
Once a tuple is created, you cannot add, remove, or change any element.
Dictionary, Mutable (Can Change)
student = {"name": "Aman", "marks": 85}
student["marks"] = 90 # Update existing key
student["city"] = "Delhi" # Add new key-value pair
del student["city"] # Delete a key-value pair
popped = student.pop("marks") # Remove and return value
print(student)
{'name': 'Aman'}
Important Methods
List Methods
marks = [85, 67, 92, 78]
marks.append(88) # Add at end -> [85, 67, 92, 78, 88]
marks.insert(1, 70) # Insert at position -> [85, 70, 67, 92, 78, 88]
marks.remove(67) # Remove value -> [85, 70, 92, 78, 88]
marks.pop(0) # Remove at index -> [70, 92, 78, 88]
marks.sort() # Sort -> [70, 78, 88, 92]
marks.reverse() # Reverse -> [92, 88, 78, 70]
marks.count(88) # Count occurrences -> 1
marks.index(78) # Find index -> 2
length = len(marks) # Length -> 4
Tuple Methods (Only 2)
marks = (85, 67, 92, 67, 78)
marks.count(67) # 2 (how many times 67 appears)
marks.index(92) # 2 (index of first occurrence of 92)
length = len(marks) # 5
Tuples have only count() and index() methods. This is a popular exam question.
Dictionary Methods
student = {"name": "Aman", "marks": 85, "city": "Delhi"}
student.keys() # dict_keys(['name', 'marks', 'city'])
student.values() # dict_values(['Aman', 85, 'Delhi'])
student.items() # dict_items([('name', 'Aman'), ('marks', 85), ('city', 'Delhi')])
student.get("name") # 'Aman'
student.update({"marks": 90, "grade": "A"}) # Update/add multiple
student.pop("city") # Remove and return value
student.clear() # Remove all items
Looping Through Each Type
Looping Through a List
marks = [85, 92, 67, 78]
for m in marks:
print(m, end=" ")
85 92 67 78
Looping Through a Tuple
marks = (85, 92, 67, 78)
for m in marks:
print(m, end=" ")
85 92 67 78
Looping Through a Dictionary
student = {"name": "Aman", "marks": 85, "city": "Delhi"}
# Loop through keys
for key in student:
print(key, ":", student[key])
# Loop through key-value pairs
for key, value in student.items():
print(key, "->", value)
name -> Aman
marks -> 85
city -> Delhi
Nesting
List of Lists
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix[1][2]) # 6
Dictionary of Dictionaries
students = {
1: {"name": "Aman", "marks": 85},
2: {"name": "Priya", "marks": 92}
}
print(students[1]["name"]) # Aman
List of Dictionaries
records = [
{"name": "Aman", "marks": 85},
{"name": "Priya", "marks": 92}
]
print(records[0]["name"]) # Aman
When to Use Which?
| Situation | Use |
|---|---|
| Marks of students that may change | List |
| Days of the week (fixed data) | Tuple |
| Student details (name, roll, marks) | Dictionary |
| Coordinates (x, y) | Tuple |
| Shopping cart items | List |
| Configuration settings | Dictionary |
| Database records | List of Dictionaries |
| Function returning multiple values | Tuple |
Common Exam Questions
Q1: What is the difference between a list and a tuple?
A list is mutable (can be changed after creation), while a tuple is immutable (cannot be changed). Lists use square brackets [] and tuples use parentheses (). Lists have more built-in methods than tuples. Tuples are faster than lists.
Q2: Can a dictionary have duplicate keys?
No. Dictionary keys must be unique. If you assign a value to an existing key, the old value is overwritten.
d = {"a": 1, "b": 2, "a": 3}
print(d) # {'a': 3, 'b': 2}
Q3: Can a list be a dictionary key?
No. Dictionary keys must be immutable. Lists are mutable, so they cannot be used as keys. Tuples can be used as dictionary keys because they are immutable.
# Valid
d = {(1, 2): "point"}
# Invalid - will cause TypeError
# d = {[1, 2]: "point"}
Q4: Write the output:
t = (10, 20, 30, 40, 50)
print(t[1:4])
print(t[-2:])
print(t[::-1])
(20, 30, 40)
(40, 50)
(50, 40, 30, 20, 10)
Q5: What is the output of len() for each?
L = [1, 2, [3, 4], 5]
T = (1, 2, (3, 4), 5)
D = {"a": 1, "b": 2, "c": 3}
print(len(L)) # 4 (nested list counts as 1 element)
print(len(T)) # 4
print(len(D)) # 3 (counts key-value pairs)
Memory Tip
Remember LTD (like a company, Limited):
- List = Locked brackets
[], Lots of methods, Liberal (mutable) - Tuple = round brackets
(), Two methods only, Tight (immutable) - Dictionary = curly braces
{}, Data in pairs, Dynamic (mutable)
Understanding these three data structures thoroughly will help you answer both theory and coding questions confidently in your CBSE exam.
Frequently Asked Questions
Is a list faster than a tuple in Python?
No. Tuples are slightly faster than lists for iteration and lookup. Because tuples are immutable, Python can optimize them more aggressively at the bytecode level. The difference is small (microseconds), but it matters when a collection is read millions of times. For data that never changes, prefer a tuple.
Is a dictionary faster than a list?
For lookup by key, yes — much faster. A list lookup like x in my_list is O(n) (linear scan), while a dictionary lookup key in my_dict is O(1) on average (hash table). For 10,000 elements, a dictionary lookup is roughly 1,000× faster than scanning a list. Use a dictionary whenever you need fast "does this key exist?" or "give me the value for this key" checks.
Can a tuple contain a list inside it?
Yes. A tuple is immutable in the sense that you cannot replace its elements, but the elements themselves can be mutable. So t = (1, 2, [3, 4]) is valid, and you can still do t[2].append(5) to mutate the inner list — even though you cannot do t[2] = "new".
Why does (5) not create a tuple in Python?
Because parentheses in Python serve two roles: grouping and tuple syntax. To disambiguate a single-element tuple, Python requires a trailing comma: (5,). Without the comma, Python treats (5) as just the integer 5 in parentheses.
When should I use a list, tuple, or dictionary in real code?
- List when you have a collection that will grow, shrink, or be sorted — student marks, log lines, items in a cart.
- Tuple when the data is fixed and represents a record — coordinates
(x, y), an RGB color, a function return with multiple values. - Dictionary when you need to look up values by a meaningful key — user profiles, configuration, counters, caches.
Can dictionary keys be a tuple?
Yes. Dictionary keys must be hashable, and tuples of hashable values are hashable. So d = {(1, 2): "point"} works. This is useful for sparse 2D grids or composite keys.
Is order guaranteed in a Python dictionary?
Yes, since Python 3.7. Dictionaries maintain insertion order as part of the language spec. Before Python 3.7 this was not guaranteed (though CPython 3.6 had it as an implementation detail).
What is the difference between del, pop, and remove for a list?
del my_list[i]removes the element at indexi(in place, no return).my_list.pop(i)removes the element at indexiAND returns it. Default is the last element.my_list.remove(value)removes the first occurrence ofvalue. RaisesValueErrorif not found.
Are list comprehensions faster than for loops?
Usually yes, by 30–50%. List comprehensions are optimized inside the CPython interpreter and avoid repeated method lookups. For short transformations, use a comprehension. For complex logic with side effects, a regular for loop is more readable.
If you want to run the code above in your browser, the Python playground executes Python 3 entirely client-side — no signup, nothing leaves your machine.
Want to learn more?
Explore free chapter-wise notes with quizzes and code playground
Prefer watching over reading?
Subscribe for free.