PEP 255: Simple Generators

Denys Duchier Denys.Duchier at ps.uni-sb.de
Wed Jun 20 14:13:00 EDT 2001


Denys Duchier <Denys.Duchier at ps.uni-sb.de> writes:

> > def zipgen(g, h):
> >     giter = g()
> >     hiter = h()
> >     while 1:
> >         yield giter.next()
> >         yield hiter.next()
> 
> which I would write as follows:
> 
> def zipgen(g,h):
>   def result(yield):
>     g(yield)
>     h(yield)
>   return result

That last part of my message flowed from my fingers into the keyboard
without being appreciably slowed down by the mush between my ears :-)
Tim was describing interleaving and I implemented concatenation which
Tim might have written as:

def concgen(g,h):
  for x in g(): yield x
  for x in h(): yield x

Cheers,

-- 
Dr. Denys Duchier			Denys.Duchier at ps.uni-sb.de
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615



More information about the Python-list mailing list