Python gives you three everyday containers for groups of values: the list, the tuple and the dictionary. They look alike at first, but each one fits a different job. By the end of this guide, you will be able to create all three, use their main operations and choose the right one for a task.

The rules here come from the data structures chapter of the official Python tutorial. Every example was run with Python 3.14, and its real output appears in the block below the code.

1. Lists: an ordered collection you can change

A list keeps items in order, and you can add, remove or reorder them after you create it. The tutorial describes lists as mutable, meaning changeable, and says their items are usually of the same kind and are usually reached by looping over the list.

marks = [72, 85, 64]
marks.append(90)
marks.sort()
print(marks)
print(marks[0], marks[-1], len(marks))
[64, 72, 85, 90]
64 90 4

append() adds an item to the end, and sort() sorts the list in place. Index 0 gives the first item and -1 gives the last one.

2. Tuples: a fixed group of values

A tuple is a group of values separated by commas, usually written inside parentheses. The tutorial calls tuples immutable: once a tuple exists, its items cannot be replaced. Tuples usually hold a mix of different kinds of values that belong together, and you read them by unpacking or indexing.

screen = (1920, 1080)
width, height = screen
print(width, height)
screen[0] = 1280
1920 1080
TypeError: 'tuple' object does not support item assignment

The second line is called sequence unpacking, and it needs one name for each item. The last line fails because tuples cannot change (only the final line of the error is shown).

3. Dictionaries: values found by key

A dictionary stores key: value pairs, and every key must be unique. You find a value by its key, not by its position. Storing a value under a key that already exists replaces the old value.

prices = {"pen": 20, "notebook": 60}
prices["ruler"] = 15
print(prices["notebook"])
print(prices.get("eraser"))
print(prices.get("eraser", 0))
for item, price in prices.items():
    print(item, price)
60
None
0
pen 20
notebook 60
ruler 15

Asking for a missing key with square brackets, as in prices["eraser"], raises KeyError: 'eraser'. The get() method returns None, or a default you choose, instead. The items() method hands you each key and value together inside a loop.

Keys must be an unchangeable type. Strings and numbers always work, and tuples work if they contain only strings, numbers or other such tuples. A tuple therefore makes a good key for a grid position:

grid = {(0, 0): "start", (2, 3): "goal"}
print(grid[(2, 3)])
goal

4. How to choose

  • Use a list when you have many items of the same kind and the collection will grow, shrink or be sorted: marks, file names or tasks.
  • Use a tuple when a small, fixed group of values describes one thing, or when you need the group to serve as a dictionary key.
  • Use a dictionary when you need to look up a value by a name or ID, such as a price by product or a setting by its name.

Speed is a second reason to pick a dictionary. Big O notation describes how the running time of an operation grows with the size of its input. The Python documentation’s page on time complexity of operations on built-in types lists x in l for a list as O(n): the time grows with the number of items. For a dictionary, key in d is O(1) on average, so the check takes about the same time however many keys there are. The page notes that these figures are for CPython and that other Python implementations may differ.

Common mistakes

  • Expecting sort() to return the list. Methods that only change a list, such as sort() and append(), return None. So result = fruits.sort() leaves result set to None. Use sorted(fruits) when you want a new sorted list and want to keep the original as it is.
  • Forgetting the comma in a one-item tuple. ("hello") is just a string. A one-item tuple needs a trailing comma: ("hello",). Running print(type(("hello")), type(("hello",))) prints <class 'str'> <class 'tuple'>.
  • Writing {} for an empty set. {} creates an empty dictionary. Use set() for an empty set.
  • Using a list as a dictionary key. Lists can change, so they cannot be keys. In Python 3.14, grid[[0, 1]] = "wall" ends with TypeError: cannot use 'list' as a dict key (unhashable type: 'list'). Use the tuple (0, 1) instead.
  • Using a list as a queue. Adding and removing at the end of a list is fast, but removing from the front is slow because every other item has to shift by one. The tutorial recommends collections.deque, which was designed for fast appends and pops at both ends.
from collections import deque
queue = deque(["first", "second", "third"])
queue.append("fourth")
print(queue.popleft())
print(queue)
first
deque(['second', 'third', 'fourth'])

In short, reach for a list when the order and number of items change, a tuple when a few values form one fixed record, and a dictionary when you look things up by name. If you are unsure, ask how you will read the data later: by position, by unpacking or by key.