simple iterator question

Arnaud Delobelle arnodel at googlemail.com
Thu Apr 2 10:38:10 EDT 2009


Neal Becker <ndbecker2 at gmail.com> writes:

> How do I interleave 2 sequences into a single sequence?

Here's a way:

>>> a = [1,2,3,4]
>>> b = [5,6,7,8]
>>> [x for S in zip(a, b) for x in S]
[1, 5, 2, 6, 3, 7, 4, 8]

> How do I interleave N sequences into a single sequence?

In the same way as above.

-- 
Arnaud



More information about the Python-list mailing list