"""Binary Search
Recursive
- 2 Separate functions
--> Perhaps more readable?
- Or just one function that recursively calls itself
--> Perhaps more logical?
"""## With 2 separate functionsdefbin_recur(lst, item):return go_bin_recur(lst, item,0,len(lst)-1)defgo_bin_recur(lst, item, low, high):if low <= high:
mid =(low + high)//2if item > lst[mid]:# To the left
low = mid +1elif item < lst[mid]:# To the right
high = mid -1else:# Foundreturn mid
return go_bin_recur(lst, item, low, high)return[]# Not found## With one functiondefbin_recur(lst, item, low=0, high=None):if high isNone:
high =len(lst)-1if low <= high:
mid =(low + high)//2if item > lst[mid]:# To the left
low = mid +1elif item < lst[mid]:# To the right
high = mid -1else:# Foundreturn mid
return bin_recur(lst, item, low, high)return[]# Not found"""Whats your preference?"""