I have parsed an xml file using the xmltodict
module and the result is stored in a dictionary of dictionaries.
Now I want to remove the special characters @
and #
in every key of the dictionary.
def remove_using_json(parse_result):
data = {}
data = json.dumps(parse_result)
#print data
#for d in data:
for key, value in data.iterkeys():
if key[0] == '@':
data[key]=key.strip("@")
elif key[0] == '#':
data[key] =key.strip("#")
It happens because your function doesn't go 'in depth'. So let's get a sample dict from @Matthew answer for example:
Your function will find only one key in this dict:
root
. But you can iterate over all items recursively in a way like that: