Brainlag
  1. Python
  2. Problem solving
39/42 lessons

Functions that call themselves

30 min4 exercisesPremium

Recursion in Python: a base case plus a smaller problem, the call stack, walking nested folders and comment threads, and what RecursionError means.

The skill
Solve a problem by handing a smaller copy of it to the same function, and walk data nested to any depth.
You make
Size counters for nested folders and a depth finder for comment threads.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 38 Searching sorted data. Free to try: Python Foundations and the playground.

Step 1 of 8
exercise_1.py

You've reached the good stuff.

4 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

Python 3.13