def unique_combinations(self, keys=None):
        """
        Returns a generator yielding the unique combination of
        elements. Both the keys of DS and the elements of the
        sets are sorted.

        When a key list (the keys argument) is supplied only the
        unique combinations of the sets specified by the keys are
        yielded by the generator.

        The combinations are sorted by slowest repeating to fastest
        repeating.
        """
        # it the keys argument is not supplied assume the
        # user wants the unique combinations of all the
        # elements of all the sets
        if keys == None:
            keys = sorted(self.keys())

        # eliminate keys to sets that have zero cardinality
        try:
            keys = [k for k in keys if k in self]
        except:
            raise TypeError("'%s' object is not iterable"
                            %type(keys).__name__)

        # if the keys list is empty we can return an empty generator
        if len(keys) == 0:
            yield
        else:
            
            # the number of unique combinations is the product 
            # of the cardinalities of the non-zero sets
            N = reduce(int.__mul__,(len(self[k]) for k in keys))

            # now we need to build a dict of generators so we
            # can build a generator or generators. To do this
            # we need to figure out the each and times
            # parameters to pass to rep()
            gen_dict = {}
            each = 1
            times = 0
            prev_n = 0
            for i, k in enumerate(reversed(keys)):
                if i != 0:
                    each *= prev_n
                times = N / (len(self[k]) * each)
                prev_n = len(self[k])

                gen_dict[k] = _rep_generator(sorted(self[k]),
                                             int(times),int(each))

            # Now we just have to yield the results
            for i in _xrange(N):
                yield [next(gen_dict[k]) for k in keys]

        Returns a generator yielding the unique combination of
        elements. Both the keys of DS and the elements of the
        sets are sorted.

        When a key list (the keys argument) is supplied only the
        unique combinations of the sets specified by the keys are
        yielded by the generator.

        The combinations are sorted by slowest repeating to fastest
        repeating.
        
recipes/Python/577702_DictSet__specialized_Pythcontainer_datatype/recipe-577702.py