Halve a sorted list with binary search
A sorted list lets you discard half of the remaining items with one comparison. Keep two bounds, lo and hi, around the part that can still contain the target. Look at the middle, then move one bound past it.
items = [2, 5, 8, 13, 21]
lo, hi = 0, len(items) - 1
mid = (lo + hi) // 2 # 2 -> items[2] is 8Think before coding
Each step removes at least the middle item, so the loop ends after about log2(n) steps. Use lo <= hi with inclusive bounds and move to mid + 1 or mid - 1, never to mid itself, or a two-item range can loop forever. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write binary_search(items, target) for a sorted list. Return an index where items holds target, or -1 when it is absent.
The explanation opens here once every check passes.