Choosing the right container is one of the first decisions in Python, and it shapes how readable and fast your code becomes. The Printable Python Beginner Cheatsheet covers lists, tuples, dictionaries and sets on its second page. This guide explains the differences and when each one earns its place.

Lists: ordered and changeable

A list keeps items in order and lets you add, remove or replace them:

tasks = ["email", "report"]
tasks.append("invoice")
tasks.insert(0, "call client")
tasks.remove("email")
print(tasks)        # ['call client', 'report', 'invoice']
print(tasks[-1])    # invoice

Use a list when order matters and the contents will change, such as a queue of tasks or a series of readings.

Tuples: ordered and fixed

A tuple is an ordered sequence that cannot be changed after it is created. This makes tuples a good choice for values that belong together, such as coordinates or a record:

point = (4, 9)
x, y = point        # tuple unpacking
print(x + y)        # 13

Because tuples are immutable, they can also be used as dictionary keys, which lists cannot. Choose a tuple when the data is a fixed group rather than a collection you will edit.

Dictionaries: key-value lookup

A dictionary maps unique keys to values. Lookups by key are fast, which makes dictionaries the usual choice for counting, grouping or matching records:

stock = {"apples": 12, "pears": 0}
stock["plums"] = 5
print(stock.get("kiwis", 0))    # 0, safe default
for item, count in stock.items():
    print(item, count)

Since Python 3.7, dictionaries keep insertion order. Use .get() when a key might be missing, and .items() when you need both keys and values in a loop.

Sets: unique items and fast membership tests

A set holds unique items with no guaranteed order. Sets are useful for removing duplicates and for comparing groups:

a = {"python", "sql", "git"}
b = {"git", "docker"}
print(a.union(b))          # all four skills
print(a.intersection(b))   # {'git'}
print("sql" in a)          # True, checked quickly

Checking whether an item is in a set is typically much faster than checking a list, especially for large collections.

A quick decision guide

  1. Need order and will change items? Use a list.
  2. Need a fixed group, or a value used as a key? Use a tuple.
  3. Need to look things up by a label? Use a dictionary.
  4. Need unique items or fast membership checks? Use a set.

Common mistakes

  • Using a list where a set would prevent duplicates automatically.
  • Trying to change a tuple. Build a new tuple instead.
  • Assuming a set keeps your original order. It does not.

Keep the decision guide next to your keyboard, or use the Printable Python Beginner Cheatsheet as a reference while you practice. Related: the full Python beginner syntax guide.