Start.dev
Back to blog

Python lists, tuples and dictionaries: when to use each

Python lists, tuples and dictionaries compared with simple examples: how each one works, how they differ, and a quick rule for picking the right one.

Ariel Weinberger
Ariel Weinberger ยท 4 min read

Lists, tuples and dictionaries are the three collections you will use in almost every Python program. They all hold several values in one variable, so beginners often wonder why Python has three of them and which one to pick.

The short answer: use a list for an ordered collection that changes, a tuple for a fixed group of values, and a dictionary when you want to look things up by name. The rest of this post shows what that means in practice.

If you are still getting started with Python, our Python roadmap for beginners shows where these collections fit in your first 30 days.

The quick comparison

ListTupleDictionary
Syntax[1, 2, 3](1, 2, 3){"a": 1, "b": 2}
OrderedYesYesYes (by insertion)
Can change after creationYesNoYes
Access byPosition (items[0])Position (point[0])Key (user["name"])
Duplicates allowedYesYesKeys must be unique
Best forA collection that grows or shrinksA fixed group of related valuesLabeled data

The two properties that matter most are mutable (can it change?) and how you access items (by position or by key). Everything else follows from those.

Lists: an ordered collection you can change

A list is the default choice. Items stay in order, you can add and remove them, and you can have as many as you like.

fruits = ["apple", "banana", "cherry"]
 
print(fruits[0])        # apple
fruits.append("mango")  # add to the end
fruits.remove("banana") # remove by value
fruits.sort()           # sort in place
 
print(fruits)           # ['apple', 'cherry', 'mango']

Reach for a list when:

  • The number of items can change, like a shopping cart or a to-do list.
  • Order matters, like a queue of tasks.
  • You want to loop over many similar items.

The beginner lessons cover each of these moves: Introduction To Lists (opens in a new tab), Indexing (opens in a new tab), Adding To A List (opens in a new tab) and Removing From A List (opens in a new tab).

Tuples: a fixed group of values

A tuple looks like a list with parentheses, but you cannot change it after you create it.

point = (3, 7)
 
print(point[0])   # 3
point[0] = 10     # TypeError: 'tuple' object does not support item assignment

That restriction is the feature. A tuple tells anyone reading your code, and Python itself, that these values belong together and should not change. Reach for a tuple when:

  • The values form one thing, like (latitude, longitude) or (red, green, blue).
  • A function returns more than one value.
  • You need a value that never changes, which also lets a tuple be used as a dictionary key.

Tuples pair nicely with unpacking, which splits a tuple into separate variables:

latitude, longitude = (51.5, -0.12)
print(latitude)   # 51.5

Tuples and unpacking are covered in Tuples (opens in a new tab) and Unpacking (opens in a new tab).

Dictionaries: labeled data you look up by key

A dictionary stores key-value pairs. Instead of asking "what is at position 2?", you ask "what is the value for email?"

user = {"name": "Ada", "age": 28, "city": "London"}
 
print(user["name"])            # Ada
user["age"] = 29               # update a value
user["language"] = "Python"    # add a new pair
print(user.get("phone", "n/a")) # n/a, no error for a missing key

Reach for a dictionary when:

  • Each value has a meaningful name, like a user profile or a settings object.
  • You need fast lookup by an ID, a word or a code.
  • You are counting or grouping things, like how many times each word appears.

To learn dictionaries step by step, start with What Is A Dictionary (opens in a new tab), then Accessing Values (opens in a new tab), Dictionary Lookup (opens in a new tab) and Looping Dictionaries (opens in a new tab).

How to choose: three questions

When you are not sure which collection to use, ask these in order:

  1. Do I need to find items by a name or ID? Use a dictionary.
  2. Should the values stay fixed once created? Use a tuple.
  3. Otherwise, will it grow, shrink or change? Use a list.

Here is one small example that uses all three. A list holds many students, each student is a dictionary, and each student's scores are stored in a tuple:

students = [
    {"name": "Ada", "scores": (90, 85, 98)},
    {"name": "Linus", "scores": (72, 88, 80)},
]
 
for student in students:
    print(student["name"], max(student["scores"]))

The list can grow as new students join. The dictionary labels each piece of data. The tuple keeps a student's three scores together as one unit. Real programs mix collections like this all the time, and Nested Lists (opens in a new tab) and Nested Dictionaries (opens in a new tab) show you how.

Common mistakes

  • Using a list when you need labels. If you catch yourself remembering that "index 2 is the email", switch to a dictionary.
  • Forgetting the one-item tuple comma. (5) is just the number 5. A one-item tuple is (5,).
  • Reading a missing dictionary key with []. user["phone"] raises a KeyError if the key does not exist. Use .get() when the key might be missing.
  • Trying to change a tuple. If you need to change the values, use a list instead.

Frequently asked questions

Is a tuple faster than a list?

Slightly, but the difference rarely matters. Choose based on whether the data should change, not on speed.

Can a dictionary have duplicate keys?

No. Each key must be unique. If you assign to a key that already exists, the old value is replaced.

Are dictionaries ordered?

Yes. Since Python 3.7, dictionaries keep the order in which items were inserted. You still look values up by key, not by position.

Where to go next

You now know the rule of thumb: lists for collections that change, tuples for fixed groups, dictionaries for labeled data. The fastest way to make it stick is to practice. Try Lists Knowledge Check (opens in a new tab) and Dictionaries Knowledge Check (opens in a new tab), then build something small with all three.

When you are ready for more, Picking A Collection (opens in a new tab) goes deeper on choosing between collections, and the course adds sets and comprehensions. For the full path from your first line of code onward, follow the Python roadmap for beginners.

Level up your coding skills

Jump into interactive courses and start building real-world projects.

Start learning

Related posts

Python or JavaScript as your first language? See the same program written both ways, where each trips beginners up, and why JavaScript takes you furthest.
Ariel Weinberger
Ariel Weinberger ยท 9 min read
A day-by-day Python roadmap for your first 30 days: what to learn, what to build each week, and the mistakes that stall most beginners.
Ariel Weinberger
Ariel Weinberger ยท 7 min read