def intervals_complement(intervals, length):
    """
	Given an iterable of sorted, nonoverlapping intervals as (start, stop)
	pairs, yield the complementary intervals. The result is equivalent to
	[(0, length)] minus the given intervals.

	>>> list(intervals_complement([(1, 2), (4, 6)], length=10))
	[(0, 1), (2, 4), (6, 10)]
	"""
    prev_stop = 0
    for start, stop in intervals:
        if start >= length:
            break
        if prev_stop != start:
            yield prev_stop, start
        prev_stop = stop
    if prev_stop < length:
        yield prev_stop, length
