Can we change the keys of a dictionary? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we change the keys of a dictionary?

5th May 2020, 5:55 AM
SARTHAK JAIN
SARTHAK JAIN - avatar
4 Answers
+ 7
Since keys are what dictionaries use to lookup values, you can't really change them. The closest thing you can do is to save the value associated with the old key, delete it, then add a new entry with the replacement key and the saved value.
5th May 2020, 6:01 AM
SITHU Nyein
SITHU Nyein - avatar
+ 2
No we can't change the keys of dictionary as they Are immutable
5th May 2020, 6:12 AM
ANJALI SAHU
+ 1
Keys of dicts are immutable
5th May 2020, 6:00 AM
Oma Falk
Oma Falk - avatar
+ 1
Code Crasher might be an accident or sth. else. Not too serious
5th May 2020, 8:31 AM
Oma Falk
Oma Falk - avatar