I am new to python, and very much enthusiastic to learn algorithm. I have written sample code for Binary search, can any one suggest how can i achieve same result in more pythonic way (Optimize the code, or using Bisect if any way possible)?
def bee_search(alist, target):
sort_list = sorted(alist)
while len(sort_list) >= 1:
end = len(sort_list)
middle = int((0 + end)/2)
if target == sort_list[middle]:
print "Found it", str(sort_list[middle])
break
elif target > sort_list[middle]:
sort_list = sort_list[middle:]
elif target < sort_list[middle]:
sort_list = sort_list[:middle]
else:
return "Fount it", str(sort_list[middle])
else:
print "List is Empty"
arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
bee_search(arr,15)