simple iterator question

John O'Hagan mail at johnohagan.com
Thu Apr 2 09:15:05 EDT 2009


On Thu, 2 Apr 2009, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?

Here's one way:

def interleave(*args):
    for n in range(min(len(i) for i in args)) :
        for i in args:
            yield i[n]

HTH,

John



More information about the Python-list mailing list