Neal Becker 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
--
htt
Sion Arrowsmith wrote:
> Neal Becker wrote:
>>How do I interleave 2 sequences into a single sequence?
>>
>>How do I interleave N sequences into a single sequence?
>
> itertools.chain(*itertools.izip(*Nsequences))
aha! thanks. andrew
--
http://mail.python.org/mailman/listinfo/python-list
Neal Becker wrote:
>How do I interleave 2 sequences into a single sequence?
>
>How do I interleave N sequences into a single sequence?
itertools.chain(*itertools.izip(*Nsequences))
--
\S
under construction
--
http://mail.python.org/mailman/listinfo/python-list
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,
>>> def xl(a):
... return list(reduce(lambda x,y:x+y,zip(*a)))
...
>>> xl([[1,2],[3,4]])
[1, 3, 2, 4]
like this?
Best Regards,
-- KDr2, at x-macro.com.
On Thu, Apr 2, 2009 at 8:32 PM, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N
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:
On Apr 2, 8:32 am, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?
http://lmgtfy.com/?q=python+interleave+sequences
http://code.activestate.com/recipes/511480/
http://code.activestate.com/recipes/528936/
HT
How do I interleave 2 sequences into a single sequence?
How do I interleave N sequences into a single sequence?
--
http://mail.python.org/mailman/listinfo/python-list