Binary Search alternate solution
my_list = [1,2,3,4,67,89]
item = 89
def binary_searach(my_list,item):
found = False
while found == False and len(my_list) > 0:
list_midpoint = len(my_list)/2
if item == my_list[int(list_midpoint)]:
found = True
elif item > my_list[int(list_midpoint)]:
my_list = my_list[int(list_midpoint)+1:len(my_list)]
else:
my_list = my_list[0:int(list_midpoint)]
return found
print(binary_searach(my_list, item))
0 answers ( 0 marked as helpful)