In this python dictionary program, we will rename key of a dictionary
Steps to solve the program
- Take a dictionary as input.
- Add a new key and assign its value to the previous key using pop().
- In this way, we will rename the key for that value.
- Print the output.
D1 = {'a':19,'b': 20,'c':21,'d':20}
D1['e'] = D1.pop('d')
print(D1)
Output :
{'a': 19, 'b': 20, 'c': 21, 'e': 20}