dictionary containing a list

Bryan Olson fakeaddress at nowhere.org
Fri Oct 6 22:48:39 EDT 2006


Ben wrote:
> I have set up a dictionary into whose values I am putting a list. I
> loop around and around filling my list each time with new values, then
> dumping this list into the dictionary. Or so I thought...
> 
> It would appear that what I am dumping into the dictionary value is
> only a pointer to the original list, so after all my iterations all I
> have is a dictionary whose every value is equal to that of the list the
> final time I looped around :-(
> 
> Is there a way to acheive what I was attempting ?

Where you "loop around ... filling [your] list", use a new
list every time. You can create a new empty list with "[]".



-- 
--Bryan



More information about the Python-list mailing list