more fun with iterators (mux, demux)

pataphor pataphor at gmail.com
Wed Apr 8 13:21:27 EDT 2009


On Wed, 08 Apr 2009 10:51:19 -0400
Neal Becker <ndbecker2 at gmail.com> wrote:

> What was wrong with this one?
> 
> def demux(iterable, n):
>     return tuple(islice(it, i, None, n) for (i, it) in 
> enumerate(tee(iterable, n)))

Nothing much, I only noticed after posting that this one handles
infinite sequences too. For smallish values of n it is acceptable. 

P.



More information about the Python-list mailing list