I have this list:
['Leistung', '15 kW', 'Farbe', 'Rot', 'Hersteller', 'Peugeot', 'Leistung', '25 kW', 'Hersteller', 'VW Nordamerika und Europa']
(I am getting this list from xml file by making a parser)and I want to convert it into a dictionary like this:
{'Leistung': ['15 kW','25 kW'], 'Farbe': 'Rot', 'Hersteller': ['Peugeot','VW Nordamerika und Europa']}
I am new to python and I have tried so many codes but it is not working
Following is my code for the parser getting the list from the xml file:
import os
from xml.etree import ElementTree
file_name = 'data.xml'
full_file = os.path.abspath(os.path.join('data', file_name))
dom = ElementTree.parse(full_file)
autos = dom.findall('auto')
n = 6
dictionary = {}
mylist = []
for a in range(n):
for c in autos:
key = c.find('Key')
value = c.find('Value')
mylist.append(key.text)
mylist.append(value.text)
break
print(mylist)