Language basics
72 steps in 13 sets of Python.
Everything you need before the interesting parts. Variables and the handful of types Python has, strings and the methods that do most of the work, flow control, the four collections, functions, and classes. Then a second pass that goes deeper on the same ground: sets and mappings, number and text handling, errors beyond a bare try, and how expressions evaluate.
It is the longest tour here at 72 steps, and deliberately so. Most of what you type in Python for the rest of your life is in this vocabulary. The Encore is complete programs rather than fragments, so you finish by typing something that actually runs.
Variables & types
- Variables and assignmentHow values get names: the very first move in any language.
- Working with numbersInteger and float arithmetic, and the operators that differ.
- Booleans and comparisonsTrue and False, and the expressions that produce them.
- Converting between typesMoving values between types with constructor calls.
- None and defaultsRepresenting absence: the value that means nothing was found.
- Unpacking sequencesPulling a sequence apart into named pieces in one statement.
Strings
- f-string formattingPython's inline template strings, with formatting built in.
- Essential string methodsThe everyday toolkit for cleaning and probing text.
- String slicingExtracting substrings by position with slice notation.
- Splitting and joiningRound-tripping between strings and lists of pieces.
- String tests & paddingInspecting and aligning text with str predicates.
- Palindrome checkA string-cleaning warm-up built on slicing.
- Slugify a titleHow titles become URL slugs.
- Anagram checkSorting as a canonical form - a common comparison trick.
- Caesar cipherThe ancient substitution cipher, as a modular-arithmetic exercise.
Flow control
- If, elif, elseBranching: choosing a path based on conditions, top to bottom.
- For loops and rangeCounting loops: range's start, stop, and step in action.
- While loopsLooping until a condition changes, not a fixed count.
- Structural pattern matchingmatch/case: branching on the shape of data, not just its value.
- FizzBuzzThe classic screening exercise for loops and conditionals.
- GCD and LCMEuclid's 2,300-year-old algorithm, still the standard GCD.
- Primality testTrial division: the simplest primality test worth writing.
Collections
- Dictionary operationsThe key-value workhorse: reading, writing, and merging dicts.
- Set operationsMembership math: unions, intersections, and differences.
- List methodsThe mutating operations every Python list supports.
- Chunk a listBatching a list into fixed-size pieces - a staple for pagination and APIs.
- Dedupe preserving orderOrder-preserving dedupe - a daily-driver data cleanup.
- Flatten nested listsRecursion handles arbitrarily nested data where plain loops get clumsy.
- Transpose a matrixRows become columns in one idiom.
- Word frequency countThe bread-and-butter pattern for tallying anything with a dict.
- Merge two sorted listsThe merge half of merge sort - two pointers over sorted inputs.
- Group items by keySQL's GROUP BY, in three lines of Python.
Functions
- Defining functionsFunction signatures: positional, keyword, and default arguments.
- *args and **kwargsVariadic functions: accepting any number of arguments.
- Lambdas and sortingTiny anonymous functions, mostly as sort keys.
- Functions as valuesFunctions are objects: pass them, store them, return them.
- RecursionFunctions that call themselves, shrinking toward a base case.
- Scope and closuresWhere names live: local, global, and captured.
Classes
- A class with methodsThe anatomy of a class: state in __init__, behavior in methods.
- Inheritance and superSubclasses: sharing a base and overriding what differs.
- PropertiesAttribute syntax with method power: computed and guarded fields.
- __repr__ and __eq__Teaching objects to print themselves and compare by value.
- Stack classThe LIFO structure underneath undo history and parsers.
Iterators, errors & files
- Iterators and nextThe protocol under every for loop: iter, next, exhaustion.
- Fibonacci generatorGenerators produce values lazily - infinite sequences without infinite memory.
- Moving averageSmoothing a stream of numbers with a sliding window.
- try, except, finallyHandling failure: catch what you expect, re-raise what you don't.
- Raising custom exceptionsNaming your failure modes with your own exception class.
- Reading and writing filesFile IO with
with: open, use, and auto-close. - Paths with pathlibFilesystem paths as objects instead of strings.
Algorithms
- Two-sum with a hash mapThe classic interview problem in linear time.
- Binary searchThe fastest way to find a value in sorted data - O(log n) beats scanning.
- QuicksortA divide-and-conquer sort that is short to write and fast in practice.
- Run-length encodingRun-length encoding: the simplest compression scheme there is.
- Depth of a nested dictMeasuring recursion depth on nested data.
Sets & mappings
- Frozen setsAn immutable set, so it can be a dict key or live inside another set.
- Dictionary viewskeys, values and items are live views, not copies.
- Sorting by a keyOne pass, one key function, and a stable order you can rely on.
Numbers & text
- The math moduleExact integer maths, careful float maths, and the constants.
- The random moduleSeeded pseudo-randomness for simulations — never for secrets.
- Format specificationsThe mini-language shared by f-strings, format and __format__.
Errors in depth
- The exception hierarchyCatch the narrowest class that covers what you can actually handle.
- else and finallyFour blocks, four jobs: try, except, else for success, finally for cleanup.
- File modesRead, write, append, exclusive and binary — and what each one destroys.
Expressions
- The walrus operatorAssign inside an expression, when the value is needed twice.
- Unpacking, furtherStarred targets, nested shapes, and unpacking into calls.
- Comparisons and truthinessChained comparisons, identity against equality, and what counts as false.
Encore
- fetch_json.pyFetch a JSON API and pretty-print it, no dependencies.
- word_freq.pyA complete CLI tool: read a file, count words, print a report.
- todo_cli.pyA complete CLI todo list persisting to JSON.
- grep_lite.pyA minimal grep: find lines matching a pattern across files.
- csv_stats.pySummary statistics for one CSV column, stdlib only.