Python Practice › Dictionary Programs › Program 89
Rename a key
Write a Python program to rename the key “d” to “e”.
Input
{"a": 19, "b": 20, "c": 21, "d": 20}Output
{'a': 19, 'b': 20, 'c': 21, 'e': 20}Approach
d["e"] = d.pop("d").
Solution
d = {"a": 19, "b": 20, "c": 21, "d": 20}d["e"] = d.pop("d")print(d)Output
{'a': 19, 'b': 20, 'c': 21, 'e': 20}Learn the concept
New to this topic? Read the lesson, then come back.