Skip to content

Data structures

Lists, tuples, dictionaries, and sets are the four built-in data structures that carry most of Python's weight. Comprehensions, slicing, and unpacking are the tools that make working with them idiomatic. This guide takes you through each structure in turn, the patterns for combining them, and the concepts that explain why Python gives you four rather than one.

Start here

If these structures are new to you, work through the Learn section in order — six short notebooks, around fifteen minutes each. Every code cell can be edited and run in place, directly on the page; no install required.

If you already know the basics and are looking for a specific technique, jump to the Recipes section, or scan the Reference for method tables and operator summaries.

What this guide covers

Learn — lists, tuples, dictionaries, sets, comprehensions, slicing and unpacking.

Recipes — sorting and filtering, merging dictionaries, nested structures, converting between structures, choosing the right structure.

Reference — method tables for lists, dictionaries, sets, and tuples, plus sequence operations common to all.

Concepts — mutable vs immutable, how hash tables power dictionaries, trade-offs between structures, memory and performance.