First occurrence
Write first_occurrence(items, target) that returns the index of the
first target in a sorted list that may contain repeats, or -1 if it is
absent.
first_occurrence([1, 2, 2, 2, 3, 5], 2) -> 1
first_occurrence([1, 2, 2, 2, 3, 5], 4) -> -1
first_occurrence([], 4) -> -1
The point is to practise binary search that keeps going after a match. One check uses a list of a million items, where a linear scan is slow but still passes; the shape is what matters here.
def first_occurrence(items, target):
...