What's the advantage over the following?:
for i in range(n):
if search(i) == val:
break
raise KeyError("not found")
found_index = i