473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

zip 2 sequences into 1

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
1 1264
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: temp | last post by:
Hi All, I wonder could someone help me with this? What I want to do is search through a list of letters and look for adjacent groups of letters that form sequences, not in the usual way of...
10
by: Vilson farias | last post by:
Greetings, I'm getting a big performance problem and I would like to ask you what would be the reason, but first I need to explain how it happens. Let's suppose I can't use sequences (it seams...
1
by: CSN | last post by:
I'm getting these errors when importing dumps: ERROR: relation "table1_id_seq" does not exist ERROR: relation "table2_id_seq" does not exist I renamed a couple tables, and the names of their...
4
by: Hemant Shah | last post by:
Folks, I have created bunch of sequences in DB2 7.2. How do I list all the defined sequences and if possible their current values? Thanks. --
1
by: J.Haan | last post by:
Hey all, does anyone know if it is in any way harmful to use a lot of sequences in a database? Does it have any disadvantages? I already noticed that sequences are hard to use with...
2
by: Peteris Krumins | last post by:
Hello, while reading through iso c standard (August 3, 1998), I noticed something I had never heard of in C: "Trigraph sequences", 5.2.1.1 The standard says: "All occurrences in a source file...
3
by: Ken | last post by:
HI: I'm reading a string that will be displayed in a MessageBox from a resource file. The string in the resource file contains escape sequences so they will be broken up into multiple lines. ...
18
by: Bruno Baguette | last post by:
Hello, I have to design a table wich will store some action reports. Each report have an ID like this 1/2004, 2/2004, ... and each years, they restart to 1 (1/2004, 1/2005, 1/2006,...). So, I...
5
by: Michael Fuhr | last post by:
I'd like to propose that certain GRANTs on a table cascade to the table's implicit sequences. In the current implementation (as of 7.4.5 and 8.0.0beta3), a table owner must typically issue GRANT...
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.