Binary search, get index

0

What I want is to get the index of the first value> = 8 by binary search. EJ: [5,10,18,19] the result would be the index of element 10.

I tried the following but it returns the empty list

def terceraParte(lista,i,j,punto):
    if j == i+1:
        res = j
    else:
        p = int((i+j)/2)
        if lista[p] >= punto:
            res = terceraParte(lista,i,p,punto)
        elif lista[p] <= punto:
            res = terceraParte(lista,p,j,punto)
    return res
lista = [5,10,18,19]
p3 = terceraParte(lista,0,len(lista),8)
    
asked by user9513682 28.03.2018 в 17:41
source

0 answers