How to keep adding values at end of dictionary

JoelB

New Member
I learnt python yesterday. I'm trying to parse an XML File and put the values in a dictionary. \[code\]xml.etree.ElementTree as ETtree = ET.parse('test.xml')root = tree.getroot()d ={ }for child in root: d[child.tag] = child.attrib print child.tag, child.attrib print("\n")for k,v in d.items(): print(k,v)\[/code\]Now the statement \[code\]d[child.tag] = child.attrib\[/code\] is being rewritten everytime instead of being updated. So the output i'm getting is -- \[code\]country {'name': 'Liechtenstein'}country {'name': 'Singapore'}country {'name': 'Panama'}('country', {'name': 'Panama'})\[/code\]The first three lines of output are due to the \[code\]print()\[/code\]. The last line is coming from dictionary. How can i do this efficiently so that my dictionary stores all the three lines?
 
Back
Top