def assign_bin(start, stop):
    """
    Given an interval `start:stop`, return the smallest bin in which it fits.

    :arg int start, stop: Interval positions (zero-based, open-ended).

    :return: Smallest bin containing `start:stop`.
    :rtype: int

    :raise OutOfRangeError: If `start:stop` exceeds the range of the binning
      scheme.
    """
    try:
        return next(dropwhile(lambda r: r[0] != r[1],
                              range_per_level(start, stop)))[0]
    except StopIteration:
        raise Exception('An unexpected error occured in assigning a bin')
Given an interval `start:stop`, return the smallest bin in which it fits.

    :arg int start, stop: Interval positions (zero-based, open-ended).

    :return: Smallest bin containing `start:stop`.
    :rtype: int

    :raise OutOfRangeError: If `start:stop` exceeds the range of the binning
      scheme.