# This is a boolean function that returns True if k is in L
# and returns False, otherwise. The function assumes that L is
# sorted in ascending (non-decreasing) order and implements
# the binary search algorithm
def binarySearch(L, k):
    # These are indices that keep track of the left
    # and right boundaries of the list that needs exploring
    left = 0
    right = len(L)-1
    
    # while left <= right, there is more to search
    while left <= right:
        middle = (left + right) // 2
        
        # Found k
        if k == L[middle]:
            return True
        
        # If k is less than L[middle] search the 
        # left half
        if k < L[middle]:
            right = middle - 1
            
        # Otherwise search the right half
        elif k > L[middle]:
            left = middle + 1
        
    return False
