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

Fast lookups and memory

35 min4 exercisesPremium

Faster Python by looking things up instead of searching: sets and dicts for membership and counting, two-sum with a dict, and functools.lru_cache.

The skill
Swap slow searches for set and dict lookups, and stop a function from redoing work it has already done.
You make
A signup filter, a cached Fibonacci and a gift card matcher that needs one pass.

Premium lesson

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

Builds on 40 Sorting by hand. 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