import bisect


def takeAdjacent(myList, myNumber, left):
    """
    Assumes myList is sorted.
    Returns closest value to myNumber on the left or right.
    """
    if left:
        pos = bisect.bisect_left(myList, myNumber)
    else:
        pos = bisect.bisect_right(myList, myNumber)
    if pos == 0: # first item or less - return first
        return myList[0]
    if pos == len(myList): # last item or more - return last
        return myList[-1]
    before = myList[pos - 1] # previous number
    after = myList[pos] # this number
    if left:
       return before
    else:
       return after