nested tuples

Tim Roberts timr at probo.com
Sat Sep 10 02:47:26 EDT 2005


"Luis P. Mendes" <luis_lupe2XXX at netvisaoXXX.pt> wrote:
>
>I'm trying to solve this problem:
>
>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)]
>
>Then, I get what I want with tuple(a).

Why?  What is it about the list of tuples that you don't like?
Philosophically, it's more in line with Guido's separation of list and
tuple.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list