def inverse(self):
        """Inverse of set as a new set."""

        newset = self.__class__.__new__(self.__class__)
        newset._min = self._min
        newset._max = self._max
        newset._ranges = []
        laststop = self._min
        for r in self._ranges:
            if laststop < r[0]:
                newset._ranges.append((laststop,r[0]))
                laststop = r[1]
        if laststop < self._max:
            newset._ranges.append((laststop,self._max))
        return newset
Inverse of set as a new set.
recipes/Python/466286_Integer_set_type/recipe-466286.py