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

Searching sorted data

30 min4 exercisesPremium

Linear versus binary search in Python: halve a sorted list until you find the item or prove it is missing, get the bounds right, then use bisect.

The skill
Find anything in a sorted list in a handful of steps, and prove when it is missing.
You make
A binary search for a leaderboard and a spending tracker.

Premium lesson

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

Builds on 37 How much work is that?. 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