By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

zip 2 sequences into 1

P: n/a
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...

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Neal Becker wrote:
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 = 'abcde'
b = range(5)
c = 'python'
from itertools import chain
list(chain(*zip(a,b,c)))

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

--
George
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.