Can't create list of dictionaries

sophie_newbie paulgeeleher at gmail.com
Fri Apr 10 13:36:43 CEST 2009


Hi there,

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.

And the function is definately returning different dictionaries each
time as I can see that when I print them.

I know this is something to do with the dictionries being stored as
references but I've no idea how to fix it seeing as the copy()
function didn't work.

Thanks!



More information about the Python-list mailing list