Rename a key

EasyDictionary Programs · 89 of 94

Write a Python program to rename the key “d” to “e”.

Advertisement
Input
{"a": 19, "b": 20, "c": 21, "d": 20}
Output
{'a': 19, 'b': 20, 'c': 21, 'e': 20}

Approach

  1. d["e"] = d.pop("d").

Solution

Python
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}
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs