Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Binary Search

Medium · 55 XP

Implement binary search returning the index of a target in a sorted list, or -1. Print the index for four targets and the number of comparisons for one of them.

Target output
0
4
9
-1
Blank · autosaved
PYbinary-search.py
Run your code to check it…
Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path