I have a dictionary in python :
aDict = {
'form-1-device': ['2'],
'form-0-test_group': ['1'],
'form-1-test_scenario': ['3'],
}
i need to remove the form-1-device with device and so on from dict . So far i have tried this:
for k,v in bDict.iteritems():
newk = [k[k.find('-',5)+1:]]
print newk
aDict[newk] = aDict[k]
del aDict[k]
or instead of
aDict[newk] = aDict[k]
del aDict[k]
This will also do the job
aDict[newk] = aDict.pop(k)
My expected output is :
aDict = {
'device': ['2'],
'test_group': ['1'],
'test_scenario': ['3'],
}
But it gives an error TypeError: unhashable type: 'list' in python dict
SO far i looked in to Python dictionary : TypeError: unhashable type: 'list' and Python, TypeError: unhashable type: 'list'
also had a look to this Python creating dictionary key from a list of items
But nothing worked for me. Any help would be appreciated.
newk = [k[k.find('-',5)+1:]]donewk = k[k.find('-',5)+1:]