In Python, I'm trying to rename the itens from dicio2, but the code is stopping before the last one:
here, I have this dict with the number and number's name:
dicio1 = {"1":"one",
"2":"two",
"3":"three",
"4":"four",
"5":"five",
"6":"six"}
and dicio2 have the number with a value:
dicio2 = {"1":"QWE",
"2":"QWE",
"3":"QWE",
"4":"QWE",
"5":"QWE",
"6":"QWE"}
This is what I need in final run:
dicio2 = {'one': 'QWE',
'two': 'QWE',
'three': 'QWE',
'four': 'QWE',
'five': 'QWE',
'six': 'QWE'}
I used this code:
for v in dicio2:
if v in dicio1:
dicio2[dicio1[v]] = dicio2.pop(v)
but the result is:
{'6': 'QWE',
'one': 'QWE',
'two': 'QWE',
'three': 'QWE',
'four': 'QWE',
'five': 'QWE'}
after that, I put a print(v):
for v in dicio2:
print(v)
if v in dicio1:
dicio2[dicio1[v]] = dicio2.pop(v)
And the result was that:
1
2
3
4
5
five
{'6': 'QWE', 'one': 'QWE', 'two': 'QWE', 'three': 'QWE', 'four': 'QWE', 'five': 'QWE'}
someone can help me why this happens? how can I do that with all the itens without crash?
The perfect mode that I needed is to rename the key without change your position, but i saw in other topic that is not possible because the key cannot be rennamed and the solution is only use the POP command to delete and create another.