A list and a dictionary are Python's two most-used ways to store a group of values: a list keeps items in order and you reach each item by its position number (its index), while a dictionary stores key–value pairs and you reach each value by its name (its key). Choose a list when the order of items matters and each item is the same kind of thing, like a queue of names. Choose a dictionary when each value needs a label, like a student's name, age and course. This guide explains both with small examples, then compares them directly so you always know which one to reach for.
What Is a Python List?
A list is an ordered collection written with square brackets. The items sit in a fixed order, and Python numbers them starting from 0: the first item is index 0, the second is index 1, and so on.
fruits = ["apple", "banana", "mango"]
print(fruits[0]) # apple
print(fruits[1]) # banana
print(len(fruits)) # 3Lists are built for change. You can add an item to the end with append(), push one into the middle with insert(), and remove items with remove() or pop():
fruits.append("orange") # ['apple', 'banana', 'mango', 'orange']
fruits.insert(1, "grapes") # grapes becomes the second item
fruits.remove("banana") # removes banana
last = fruits.pop() # removes and returns 'orange'A list may hold duplicates happily — ["pen", "pen", "pencil"] is perfectly valid, because nothing identifies an item except its position. Items can also be of mixed types, although in real code a list usually holds one kind of thing: all names, all prices, or all temperatures. If you have worked through our comparison of Python list vs tuple and their differences, you already know the list's close cousin; the dictionary in the next section is a bigger change of thinking.
What Is a Python Dictionary?
A dictionary (often shortened to dict) stores pairs: a key and its value, written with curly brackets and a colon between each pair. Keys are usually short strings that describe the value, which makes dictionary code read almost like English.
student = {
"name": "Meera",
"age": 17,
"course": "Python"
}
print(student["name"]) # Meera
print(student["course"]) # PythonYou add a new pair, or change an existing one, by assigning to a key. Deleting uses the del statement or pop():
student["city"] = "Pune" # add a new pair
student["age"] = 18 # change an existing value
del student["course"] # remove a pair
age = student.pop("age") # remove and return the valueTwo rules matter. First, keys must be unique: if you assign to the same key twice, the second value quietly replaces the first. Second, a missing key raises a KeyError when you use square brackets, so cautious code uses student.get("city", "Unknown"), which returns a default instead of crashing. The official Python tutorial chapter on data structures at docs.python.org works through both types in more depth, including list methods you will use daily.
Lists and Dictionaries Working Together
Real programs rarely choose one type forever — they combine them. The most common pattern in all of Python is a list of dictionaries: each dictionary describes one record, and the list holds all the records in order.
students = [
{"name": "Meera", "age": 17, "course": "Python"},
{"name": "Tom", "age": 18, "course": "JavaScript"},
{"name": "Sana", "age": 17, "course": "Python"}
]
print(students[0]["name"]) # Meera
print(students[2]["course"]) # PythonRead it in two steps: students[0] picks the first dictionary by position, then ["name"] picks a value by key. This is exactly the shape of data you receive from web APIs and JSON files, so getting comfortable with it early pays off everywhere. The reverse also exists — a dictionary whose values are lists, such as courses mapped to their enrolled students.
Looping Over Each Type
Looping shows the personality difference clearly. A list loop hands you each item directly:
for fruit in fruits:
print(fruit)A dictionary loop hands you the keys by default. Use .items() when you need keys and values together, which is most of the time:
for key, value in student.items():
print(key, ":", value)If you only need the values, .values() gives them without the keys. Beginners often write for key in student: print(student[key]) — it works, but .items() is shorter and clearer. Programmers coming from JavaScript will recognise a familiar pattern here, and our guide to JavaScript array methods explained with examples makes a good side-by-side read on how another language loops and transforms collections.
List vs Dictionary: Side-by-Side Comparison
| Feature | List | Dictionary |
|---|---|---|
| Written as | [ ] square brackets |
{ } curly brackets with key: value pairs |
| How you reach an item | By index number: fruits[0] |
By key: student["name"] |
| Order | Order is the whole point; position means something | Pairs keep insertion order, but you find them by key, not position |
| Duplicates | Allowed freely | Values may repeat; keys must be unique |
| Best for | A sequence: names, scores, steps, queue of tasks | A record: one thing described by labelled facts |
| Typical question | "What is the third item?" | "What is this student's course?" |
One more difference hides under the surface: looking something up by key in a dictionary stays fast even with a million pairs, because Python jumps straight to the key. Finding an item in a list by value means checking items one by one. The built-in types reference at docs.python.org documents these behaviours formally if you want the precise rules later.
Which Should You Use? A Simple Decision Guide
Ask yourself three questions. First: will I look things up by a name or ID? If yes, use a dictionary. Second: does the order matter, and will I process items one after another from start to finish? If yes, use a list. Third: am I describing one thing with several facts (a person, a product, a book)? That is a dictionary. Am I collecting many similar things (people, products, books)? That is a list — very often a list of dictionaries, as you saw above.
Worked examples make it stick. A shopping cart is a list (items in the order added) of dictionaries (each item has a name, price and quantity). A phone book is a dictionary (name → number). A playlist is a list. A single song's details form a dictionary. When in doubt, beginners usually need a list first and add dictionaries inside it when each item grows beyond a single value.
Common Beginner Mistakes
Using a dictionary like a list. Writing student[0] fails, because dictionaries are reached by key, not position. If you truly need positions, you probably wanted a list.
Expecting list indexes to start at 1. They start at 0 in Python, so the last item of a three-item list is index 2, and fruits[3] raises an IndexError.
Repeating a dictionary key by accident. Typing the same key twice in one dictionary does not store both values — the second silently wins, and the first is lost.
Changing a list while looping over it. Removing items inside a for loop over the same list skips elements. Loop over a copy (fruits[:]) or build a new list instead. These small traps catch everyone once; recognising them quickly is most of the cure.
FAQ
Is a dictionary ordered in Python?
Yes, since Python 3.7 dictionaries remember the order in which pairs were added, and loops follow that order. Even so, you still reach values by key, not by position, which is the real difference from a list.
Can a list contain a dictionary, and the other way round?
Yes, both ways. A list of dictionaries is the standard way to store records like students or products, and a dictionary value can itself be a list, such as a student mapped to their marks.
Which is faster, a list or a dictionary?
For looking something up by name or ID, a dictionary is far faster, especially with lots of data. For simply storing items in order and reading them in sequence, a list is simpler and just as fast in practice.
Can dictionary keys be numbers?
Yes. Keys can be strings, numbers or tuples — any immutable type. In practice, string keys are the most common because they make the code read like plain English.
How do I check whether a key exists in a dictionary?
Use the in operator: "city" in student returns True or False without raising an error. Alternatively, call .get() with a default value, which safely returns the default when the key is missing.
Conclusion
Lists store items in order, reached by number; dictionaries store labelled facts, reached by key. Neither is "better" — they answer different questions, and real programs combine them constantly, most often as a list of dictionaries. Practise by modelling something familiar both ways — your class register, a shopping cart, a playlist — and the choice will soon become automatic every time you write Python.
Leave a Comment