I have this dictionary.
maximo = {'CodChamado': 50, '_14984|Top Down:': 0, '_14985|Hierarquia solicitante:': 0}
And I want to change these keys "_14984|Top Down:"
and "_14985|Hierarquia solicitante:"
to
new_key = ['Campo Extra|Top Down:', 'Campo Extra|Hierarquia solicitante:']
The result of that is the new dictionary:
new_maximo = {'CodChamado': 50, 'Campo Extra|Top Down:': 0, 'Campo Extra|Hierarquia solicitante:': 0}
I tried to do this but it doesn't work:
old_key = []
for key in self.maximo:
if key[0] == "_":
old_key.append(key)
for i in new_key:
for j in old_key:
self.maximo[i] = self.maximo[j]
del self.maximo[j]
This error appears:
File "<string>", line 3, in <module>
KeyError: '_14984|Top Down:'
Anyone knows how to do it?
I need it to be done kind of dynamic because this is not the only dictionary I'm using, but all of the keys I need to change have this pattern with "_"
in key[0]
.