list to tuple

Z

zxo102

Hi,
I got several dynamic lists a1, b1, c1, .... from a python
application such as
a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, ....

With python, I would like to reorganize them into a tuple like

t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...)

Anybody knows how to do that. Thanks for your help.

Ouyang
 
J

James Stroud

Try the zip funciton:

py> a = [11,12,13,14]
py> b = [2,3,4,5]
py> c = [20,21,22,23,24,25]

py> zip(a,b,c)
[(11, 2, 20), (12, 3, 21), (13, 4, 22), (14, 5, 23)]



Hi,
I got several dynamic lists a1, b1, c1, .... from a python
application such as
a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, ....

With python, I would like to reorganize them into a tuple like

t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...)

Anybody knows how to do that. Thanks for your help.

Ouyang



--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
R

Ruslan Spivak

zxo102 said:
Hi,
I got several dynamic lists a1, b1, c1, .... from a python
application such as
a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, ....

With python, I would like to reorganize them into a tuple like

t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...)

Anybody knows how to do that. Thanks for your help.

t1 = tuple(zip(a1, b1, c1))

I don't know your requirements, so consider also izip from itertools.

Ruslan
 

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

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,986
Latest member
ColbyG935

Latest Threads

Top