def binary_search(c,b):
    """
    Returns index of first occurrence of c in b; -1 if not
    found.

    Parameter b: The sequence to search
    Precondition: b is a SORTED sequence

    Parameter c: The value to search for
    Precondition: NONE (c can be any value)
    """
    # Quick way to check if a sequence; CANNOT easily check sorted
    assert len(b) >= 0, repr(b)+' is a not a sequence (list, string, or tuple)'

    # Store in i the value BEFORE beginning of range to search
    i = 0
    # Store in j the end of the range to search (element after)
    j = len(b)
    # The middle position of the range
    mid = (i+j)//2

    while j > i:
        if b[mid] < c:
            i = mid+1
        else:     # b[mid] >= c
            j = mid

        # Compute a new middle.
        mid = (i+j)//2

    if i < len(b) and b[i] == c:
        return i

    # NOT FOUND
    return -1