473,386 Members | 1,621 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,386 software developers and data experts.

list to tuple

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

Aug 12 '05 #1
4 1530

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)]

On Thursday 11 August 2005 09:05 pm, zxo102 wrote:
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/
Aug 12 '05 #2
"zxo102" <zx****@gmail.com> writes:
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

Aug 12 '05 #3
Try this:
a,b,c = list('tab'),list('era'),list('net')
a,b,c (['t', 'a', 'b'], ['e', 'r', 'a'], ['n', 'e', 't']) tuple(((x,y,z) for x,y,z in zip(a,b,c))) (('t', 'e', 'n'), ('a', 'r', 'e'), ('b', 'a', 't'))


- Paddy.

Aug 12 '05 #4
Thanks for your help.

Aug 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Fuzzyman | last post by:
Pythons internal 'pointers' system is certainly causing me a few headaches..... When I want to copy the contents of a variable I find it impossible to know whether I've copied the contents *or*...
9
by: Yomanium Yoth Taripoät II | last post by:
HI, 1) what are the differences between list and tuple? 2) how to concatenate tuple and list? no method, no opérator? 3) im looking the fucking manual, and cant add value in my tuple, when it...
4
by: GrelEns | last post by:
hello, i wonder if this possible to subclass a list or a tuple and add more attributes ? also does someone have a link to how well define is own iterable object ? what i was expecting was...
2
by: Ishwar Rattan | last post by:
I am a little confused about a list and a tuple. Both can have dissimilar data-type elements, can be returned by functions. The only difference that I see is that list is mutable and tuple is...
16
by: flyaflya | last post by:
a = "(1,2,3)" I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', '2', ',', '3', ')') not (1,2,3)
5
by: Xah Lee | last post by:
suppose i'm going to have a data structure like this: , , , , .... ] should i use (width,height) or ?
6
by: fdu.xiaojf | last post by:
Hi all, I can use list comprehension to create list quickly. So I expected that I can created tuple quickly with the same syntax. But I found that the same syntax will get a generator, not a...
25
by: beginner | last post by:
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform or ] to . Another question is how do I pass a tuple or list of all the aurgements of a function to...
3
by: Davy | last post by:
Hi all, I am curious about whether there is function to fransform pure List to pure Tuple and pure Tuple to pure List? For example, I have list L = ,] something list2tuple() will have...
0
by: Hatem Nassrat | last post by:
on Wed Jun 13 10:17:24 CEST 2007, Diez B. Roggisch deets at nospam.web.de wrote: Well I have looked into this and it seems that using the list comprehension is faster, which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.