Can we change the keys of a dictionary? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Can we change the keys of a dictionary?

5th May 2020, 5:55 AM
SARTHAK JAIN
SARTHAK JAIN - avatar
4 Respostas
+ 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