A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/354166.html below:

nested tuples

nested tuplesMax Erickson maxerickson at gmail.com
Fri Sep 9 15:22:15 EDT 2005
"Luis P. Mendes" <luis_lupe2XXX at netvisaoXXX.pt> wrote in
> suppose I'm reading a csv file and want to create a tuple of all
> those rows and values, like ((row1value1, row1value2,
> row1value3),(row2value1, row2value2, row2value3),...,
> (rowNvalue1, rowNvalue2, rowNvalue3)) 
> 
> I haven't found the way to do it just using tuples.  How can I do
> it? 
> 
> Nevertheless, I can solve it like this:
> a=[]
> 
> for row in reader:
> ~   elem = (row[0],row[1],row[2])
> ~   a.append(elem)
> 
> which will result in a list of tuples: [(row1value1, row1value2,
> row1value3),(row2value1, row2value2, row2value3),...,
> (rowNvalue1, rowNvalue2, rowNvalue3)]

tuple() will consume a list.

>>> tuple([1,2,3])
(1, 2, 3)
>>> tuple([(1,2),(3,4),(5,6)])
((1, 2), (3, 4), (5, 6))


max

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4