xmltodict does not return a list for one element
问题 The following Code produces an error, if there is only one "car" in "garage": import xmltodict mydict = xmltodict.parse(xmlstringResults) for carsInGarage in mydict['garage']['car']: # do something... The Reason is that mydict['garage']['car'] is only a list if there is more than one element of "car". So I did something like this: import xmltodict mydict = xmltodict.parse(xmlstringResults) if isinstance(mydict['garage']['car'], list): for carsInGarage in mydict['garage']['car']: # do