[Tutor] [tutor] creating list of tuples

Kent Johnson kent37 at tds.net
Tue Feb 26 03:52:52 CET 2008


Varsha Purohit wrote:
> Hello all,
>        In my application i have to create a list of tuples. I have a for 
> loop which will create (x,y) tuple each time it iterates, and i ahve to 
> store each tuple in a list like
> 
> list1= [(x1,y1), (x2,y2).....]
> 
> any ideas how to do that ???

list1 = []
for ...
   # code to create x and y
   list1.append( (x, y) )

Note you do need the double parentheses; the inner pair creates a tuple, 
the outer pair is for the function call.

Kent


More information about the Tutor mailing list