Can't create list of dictionaries
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Apr 11 12:32:30 EDT 2009
> On Apr 10, 12:36 pm, sophie_newbie <paulgeele... at gmail.com> wrote:
>>
>> I've got a function that returns a dictionary, I need to loop and
>> return 1000 dictionaries and append them to a list, but the thing is
>> that when I do the list.append(funtThatReturnsDict()) the resulting
>> only ever has 1 dictionary attached to it, even after running the
>> append function 1000 times!
>>
>> I've tried using dict.copy() on the dictionary that was returned from
>> the function but this didn't work either.
En Fri, 10 Apr 2009 08:49:12 -0300, sophie_newbie <paulgeeleher at gmail.com>
escribió:
> Scratch everything I said, copy() does work. Made a wee mistake
> somewhere else.
If the function is supposed to return a *different* dictionary each time,
ensure that, don't "fix" the result value after it has returned.
--
Gabriel Genellina
More information about the Python-list
mailing list