def get_remaining_intervals(all_indices, intervals_to_subtract):
    """Yield intervals as 2-tuples from remaining indices."""
    ### start by grabbing all remaining indices (those which
    ### don't belong to the intervals to subtract)

    remaining_indices = set(
        ## make a set out of the indices
        set(all_indices)
        ## then remove indices from each interval gathered
        ## in a set
        - set(
            ## chain all the ranges together, so their
            ## indices are all gathered
            chain.from_iterable(
                ## get the ranges of all the intervals
                range(including_start, excluding_end)
                for including_start, excluding_end in intervals_to_subtract
            )
        )
    )

    ## then retrieve and return the intervals formed by
    ## the remaining indices
    return get_intervals(remaining_indices)
Yield intervals as 2-tuples from remaining indices.
nodezator/ourstdlibs/mathutils.py