Re: building lists of dictionaries

2006-07-23 Thread Ernesto García García
> parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 With this, you are creating a list with 6 references to the same list. Note that the left operand of '*' is evaluated only once before "multiplying" it six times. Regards, Tito -- http://mail.python.org/mailman/listinfo

Re: building lists of dictionaries

2006-07-23 Thread Rob Williscroft
Jean_Francois Moulin wrote in news:[EMAIL PROTECTED] in comp.lang.python: > Hi all, > > I tried this piece of code (FWIW, it was taken as is from a help > section of mpfit, a mathematical routine for least square fitting): > > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], > 'limits':[0.,

Re: building lists of dictionaries

2006-07-23 Thread Tim Chase
> parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 > parinfo[0]['fixed'] = 1 > parinfo[4]['limited'][0] = 1 > parinfo[4]['limits'][0] = 50. > > The first line builds a list of six dictionaries with > initialised keys. I expected that the last three lines > would o

Re: building lists of dictionaries

2006-07-23 Thread Juho Schultz
Jean_Francois Moulin wrote: > Hi all, > > I tried this piece of code (FWIW, it was taken as is from a help section of > mpfit, a mathematical routine for least square fitting): > > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 > The first line builds a list of six dicti

Re: building lists of dictionaries

2006-07-23 Thread Juho Schultz
Tim Chase wrote: > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], > 'limits':[0.,0.]}.copy() for i in xrange(0,6)] > > However, this will still reference internal lists that have > been referenced multiple times, such that > > >>> parinfo[5]['limited'] > [0, 0] > >>> parinfo[4]['limited'][

Re: building lists of dictionaries

2006-07-23 Thread Ernesto García García
>>parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], >>'limits':[0.,0.]}.copy() for i in xrange(0,6)] >> >>However, this will still reference internal lists that have >>been referenced multiple times, such that >> >> >>> parinfo[5]['limited'] >>[0, 0] >> >>> parinfo[4]['limited'][0] = 2 >> >>> par

Re: building lists of dictionaries

2006-07-23 Thread Tim Chase
>>parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], >>'limits':[0.,0.]}.copy() for i in xrange(0,6)] >> >>However, this will still reference internal lists that have >>been referenced multiple times, such that >> >> >>> parinfo[5]['limited'] >>[0, 0] >> >>> parinfo[4]['limited'][0] = 2 >> >>> par