def partition_range(stop, annotations=None):
    annotations = annotations or []
    partitioning = []
    part_start, part_levels = 0, None
    for p in sorted(set(itertools.chain([0, stop],
                                        *itertools.chain(*annotations)))):
        if p == stop:
            partitioning.append( (part_start, p, part_levels) )
            break
        levels = {level for level, regions in enumerate(annotations)
                  if any(x <= p < y for x, y in regions)}
        if p == 0:
            part_levels = levels
            continue
        if levels != part_levels:
            partitioning.append( (part_start, p, part_levels) )
            part_start, part_levels = p, levels
    return partitioning