zip 2 sequences into 1

N

Neal Becker

What's an easy/efficient way to zip together 2 (or more) sequences into a
single sequence?

I noticed zip builtin. This combines

a_0 ... a_n
b_0 ... b_n

into

(a_0 b_0)(a_1 b_1)...

What I want is a single sequence

a_0 b_0 a_1 b_1...
 
G

George Yoshida

Neal said:
What's an easy/efficient way to zip together 2 (or more) sequences into a
single sequence?
How about

itertools.chain(*zip(seq1, seq2, seq3, ...))

For example:
['a', 0, 'p', 'b', 1, 'y', 'c', 2, 't', 'd', 3, 'h', 'e', 4, 'o']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top