def _get_bin(value, bins):
    """Returns the smallest index i of bins so that
    bin[i][0] <= value < bin[i][1], where
    bins is a list of tuples, like [(0,20), (20, 40), (40, 60)]
    """

    for i in range(0, len(bins)):
        if bins[i][0] <= value < bins[i][1]:
            return i
    return -1