Level 2: Intermediate Python Exercises
You know the basics — now write code that's cleaner, more flexible and harder to
break. Level 2 covers the techniques that separate scripts that work from code
that's Pythonic: idiomatic loops with enumerate and zip, functions that
accept any arguments, custom sorting, recursion, the collections module,
inheritance and robust error handling.
The graph has three starting points — String Methods, enumerate & zip and Error Handling — so you can begin with whichever interests you most. Everything comes together in the Grade Book capstone, where you parse messy real-world input, skip broken lines safely and compute averages per student.
The 12 exercises in this level
- 1 String Methods Clean and format text Real-world text is messy. Clean it up with Python's built-in string methods and build new text with f-strings. Start here — no prerequisites
- 2 enumerate & zip Loop like a Pythonista Stop juggling index variables. enumerate counts for you and zip walks several lists side by side. Start here — no prerequisites
- 3 Error Handling try / except Programs meet bad input. Catch exceptions so your code fails gracefully instead of crashing. Start here — no prerequisites
- 4 Flexible Arguments *args and **kwargs Write functions that accept any number of positional and keyword arguments — the trick behind print() and many library APIs. Recommended first: String Methods
- 5 Sorting & Lambdas Custom sort keys Sort any data the way you need it using key functions and short anonymous lambda functions. Recommended first: enumerate & zip
- 6 Recursion Functions that call themselves Some problems contain smaller copies of themselves. Solve them with a function that calls itself until it reaches a simple base case. Recommended first: enumerate & zip
- 7 Counter & defaultdict The collections module Counting and grouping are everyday tasks. The collections module turns them into one-liners. Recommended first: String Methods, Sorting & Lambdas
- 8 Inheritance Reuse classes with super() Build specialised classes on top of general ones: inherit behaviour, override what's different, and reuse the parent with super(). Recommended first: Flexible Arguments
- 9 Grade Book Capstone — parse, group, average Put the level together: read messy score lines, skip the broken ones safely, group scores by student and compute averages. Recommended first: Error Handling, Counter & defaultdict
- 10 Slicing Take part of a string or list Cut out part of a string or list with [start:stop], and reverse it with [::-1]. Recommended first: String Methods
- 11 Sets Unique items and overlaps Remove duplicates and find what two collections have in common with Python sets. Recommended first: enumerate & zip
- 12 Dict Comprehensions Build a dictionary in one line Turn a list of pairs into a dictionary in one readable line, keeping only the entries you want. Recommended first: Sets
Frequently asked questions
- Should I finish Level 1 before starting Level 2?
- It's recommended but not required. If you're comfortable with variables, loops, functions, lists and dictionaries, you can start Level 2 directly — every level is open.
- Which exercise should I start with?
- Any of the three topics in the top row of the graph: String Methods, enumerate & zip or Error Handling. Each has no prerequisites within this level.
- What is a capstone exercise?
- A capstone combines several skills from the level in one realistic task. Grade Book uses error handling, defaultdict and dictionary comprehensions together, which is a good test that you've really understood them.
- Are these topics used in real projects?
- Constantly. Parsing text, counting and grouping data with Counter and defaultdict, sorting with key functions and handling bad input with try and except appear in almost every real Python codebase.