This code is meant to do a binary search of a sorted list containing integers.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures for an upcoming coding interview.
def bin_search(a, item):
first = 0
last = len(a) - 1
found = False
while first <= last and not found:
mid = (first + last) // 2
if a[mid] == item:
found = True
else:
if item < a[mid]:
last = mid - 1
else:
first = mid + 1
return found