question about generators

Delaney, Timothy tdelaney at avaya.com
Thu Aug 22 01:20:38 CEST 2002


> From: Andrew Koenig [mailto:ark at research.att.com]
> 
> 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.

And one of the major points of using generators is ... to avoid building
potentially very large lists ...

Tim Delaney




More information about the Python-list mailing list