question about generators

Andrew Koenig ark at research.att.com
Wed Aug 21 15:06:14 CEST 2002


>> def product(s, *sets):
>>     if not sets:
>>         for x in s:
>>             yield (x,)
>>     else:
>>         subproduct = list(product(*sets))
>>             for x in s:
>>                 for t in subproduct:
>>                     yield (x,) + t

Delaney> As we can see, there are two sections of the format:

Delaney>     for x in <seq>:
Delaney>         yield <something>

Delaney> However, in neither case would you be able to use

Delaney>     yield every <seq>

    def product(s, *sets):
        if not sets:
            yield every [(x,) for x in s]
        else:
            subproduct = list(product(*sets))
                yield every [(x,) + t for x in s for t in subproduct]

I should think that would work as long as "yield every" takes an
iterable rather than just a generator.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list