List of Dictionaries
Lenny Self
lenny_self at hotmail.com
Thu Mar 7 18:59:01 EST 2002
I am having a problem I was hoping someone might be able to help me
with. I am attempting to append several dictionaries to a list for
further processing, however I am seeing some rather odd behavior.
When I add the first dictionary element to the list all is well. When
I add the second element to the list both the first and second element
reference the second dictionary that was added. The behavior
continues whenever I add an element. So, if I add, say 50
dictionaries, all of the listes elements reference the last dictionary
I added.
I don't have the code with me right now, but I can assure you it is
easy as this:
allMail = [...] # list of mail objects
dictsList = []
for mail in allMail:
dictsList.append(mail.getData()) # getData returns a dictionary
I have tried this code with both Python 2.1.1 and 2.2. Same behavior.
Also, I am positive that each of the objects I attempt to append to
the list are different.
Any suggestions? Any help would be great.
Thanks.
-- Lenny
More information about the Python-list
mailing list