PythiloLesson 4 of 8 · progress kept in this browser

Find a boundary instead of an exact match

Binary search can locate the first position where a predicate changes from false to true. Searching for the first value at least a target handles missing values and duplicates without special cases. Use a half-open interval: the answer always lies between left and right, and right may be the length of the list.

from bisect import bisect_left
print(bisect_left([2, 4, 4, 9], 4))
Your task

Implement lower_bound(items, target) without importing bisect. Return the first index with items[index] >= target in a sorted list, or len(items) if every value is smaller.