[Tutor] [tutor] creating list of tuples
Varsha Purohit
varsha.purohit at gmail.com
Tue Feb 26 05:09:45 CET 2008
I think i got it....
i m creating a tuple of 2 elements everytime and i m adding it to a list. i
m creating a new tup everytime and adding it to a list....
for x in file:
value=0
tup = ()
for developerAgent in developers:
#print developerAgent.disutility
value +=developerAgent.disutility
tup = (value,globalVar.cntr)
globalVar.cntr +=1
globalVar.disutilList.append(tup)
print globalVar.disutilList
i am getting output as what i described...
thanks for the help :)
On Mon, Feb 25, 2008 at 6:52 PM, Kent Johnson <kent37 at tds.net> wrote:
> 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
>
--
Varsha Purohit,
Graduate Student
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080225/463b7f43/attachment.htm
More information about the Tutor
mailing list