Python Tutoring Online
 Home

Python Dictionary vs List

The core difference between a Python dictionary and a list is how data is accessed: a list stores values in an ordered sequence accessed by numeric index, while a dictionary stores values as key-value pairs accessed by key. Both are mutable and can hold mixed data types, but they're built for different jobs.

In this tutorial you will learn how each structure works, how their performance compares for lookups and searching, when to use one over the other, how they behave when nested together, and the mistakes beginners make most often.

Need Help Learning Python?

Understanding Python data structures like lists and dictionaries is essential for programming and data science.

Many beginners struggle to choose the right data structure for their problem.

Get Python Tutoring Help

What is a Python List

A list is an ordered, mutable collection of elements. Items are accessed by their position, called an index, starting at 0. Lists are defined with square brackets.

Example

Python
numbers = [10, 20, 30, 40]

print(numbers)
print(numbers[1])

Output


[10, 20, 30, 40]
20

The list preserves the order items were added in, and numbers[1] retrieves the second element — index 1 — since Python indexing starts at 0.

What is a Python Dictionary

A dictionary is an unordered-by-access, mutable collection of key-value pairs. Each value is retrieved using its unique key rather than a numeric position. Dictionaries are defined with curly braces.

Example

Python
student = {
"name":"Alice",
"age":21,
"course":"Python"
}

print(student)
print(student["name"])

Output


{'name': 'Alice', 'age': 21, 'course': 'Python'}
Alice

Each value is labeled with a key that describes what it represents, which makes dictionaries easier to read than a list when the data has meaning attached to it, such as a person's name or age.

Main Differences Between Dictionary and List

Feature List Dictionary
Structure Ordered sequence of values Key-value pairs
Access Method Numeric index (0, 1, 2...) Key
Syntax Square brackets [] Curly braces {}
Duplicates Allowed for values Keys must be unique; values can repeat
Lookup by value O(n) — scans the list O(1) average — hash table lookup by key
Order Preserves insertion order, position-based Preserves insertion order, but accessed by key, not position
Typical use case Ordered collections of similar items Labeled or structured data

Side-by-Side Example

The same information can be represented either way — the difference is how it's accessed afterward.

Python
# Using a list
student_list = ["Alice", 21, "Python"]

print(student_list[0])


# Using a dictionary
student_dict = {
"name":"Alice",
"age":21,
"course":"Python"
}

print(student_dict["name"])

Output


Alice
Alice

Both return "Alice", but the dictionary version is self-documenting — student_dict["name"] is clearer than student_list[0], which requires remembering that position 0 means "name."

Performance: Searching for Data

This is one of the most practical differences between the two structures. Searching a list for a value checks each element one at a time, which gets slower as the list grows. Searching a dictionary by key uses a hash table, which stays fast regardless of size.

Python
# Searching in a list — O(n)
numbers = [10,20,30,40]
print(30 in numbers)

# Searching in a dictionary — O(1) average
student = {"name":"Alice","age":21}
print("age" in student)

Output


True
True

Both return True, but for large datasets, checking in on a dictionary stays roughly constant-time no matter how many keys it has, while checking in on a list gets slower as the list grows, since Python has to scan through it element by element.

Nesting Lists and Dictionaries Together

Lists and dictionaries are frequently combined — a common real-world pattern is a list of dictionaries, used to represent multiple structured records.

Python
students = [
{"name":"Alice","age":21},
{"name":"Bob","age":23}
]

for student in students:
    print(student["name"])

Output


Alice
Bob

This pattern — a list of dictionaries — is exactly how most APIs return collections of records, such as a list of users or a list of products, each represented as its own labeled dictionary.

Real-World Use Cases

When to Use a List

When to Use a Dictionary

Common Beginner Mistakes

Frequently Asked Questions

What is the main difference between a dictionary and a list in Python?

A list stores values in order and accesses them by numeric index. A dictionary stores values as key-value pairs and accesses them by key instead of position.

Which is faster, a dictionary or a list?

For checking whether a value exists or looking something up by a label, a dictionary is faster on large data, since it uses a hash table for near-constant-time lookups. For accessing an item at a known position, both are equally fast.

Can a dictionary have duplicate values?

Yes. Dictionary values can repeat freely — only the keys must be unique.

Can I use a list as a dictionary key?

No. Dictionary keys must be hashable, and lists are mutable, so they can't be used as keys. Use a tuple instead if you need a sequence as a key.

Should I use a list of dictionaries or a dictionary of dictionaries?

Use a list of dictionaries when each record doesn't need a unique identifier and you'll process them in order. Use a dictionary of dictionaries when each record has a natural unique key, like a user ID, that you'll look up directly.

Related Python Dictionary Tutorials


Stuck Learning Python?

Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.

Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.

  • Fix your Python code
  • Get help with assignments
  • Real World Python Projects

Get Python Tutoring Help



Stuck Learning Python?

Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.

Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.

    Get Python Tutoring

PythonTutor.net

Home    Tutorial     Online Live Trainings    Contact Us           © 2026 All rights reserved by www.PythonTutor.net