Python Iterables struggling using map() built-in

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Dec 8 00:06:44 EST 2014


Terry Reedy wrote:
> However, this 'beautiful' code has a trap.  If one gets rid of the 
> seemingly unneeded temporary list res by telescoping the last two lines 
> into a bit too much into
> 
>             yield tuple(next(i) for i in iters)
> 
> we now have an infinite generator, because tuple() swallows the 
> StopIteration raised as a side-effect of next calls.

An excellent example of the kind of thing that PEP 479
is designed to catch! There couldn't be a better
advertisement for it. :-)

-- 
Greg



More information about the Python-list mailing list