0
def binary_search_aux(v, seq, lo, hi):
    if lo > hi: 
        return False
    mid = (lo + hi) // 2
    if v == seq[mid]:
        return True
    elif v < seq[mid]:
        binary_search_aux(v, seq, lo, mid-1)
    else:
        binary_search_aux(v, seq, mid+1, hi)

def binary_search(v, seq):
    return binary_search_aux(v, seq, 0, len(seq)-1)


lst = [1, 2, 3, 4, 5]
print(binary_search(4,lst))

Could someone please explain why this code is returning None instead of what I intended it to return (True)?

Thanks in advance

Schwaino
  • 1
  • 2

0 Answers0