return r < len(indices) and indices[r] < b

def check(byvalue, x, a, b):
    indices = byvalue.get(x, None)
if not indices:
    return False
return has_index_in_slice(indices, a, b)
Fast membership in slices of lists