> 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
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.,
> 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
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
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'][
>>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
>>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