simple iterator question
andrew cooke
andrew at acooke.org
Thu Apr 2 09:05:42 EDT 2009
Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?
don't know if there's a better way, but
from itertools import izip
def interleave(*doodahs):
for together in izip(*doodahs):
for single in together:
yield single
seems like it should work (warning: untried).
will terminate on shortest length doodah.
andrew
More information about the Python-list
mailing list