Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (45.3k points)

I want to change the key of an entry in a Python dictionary.

Is there a straightforward way to do this?

1 Answer

0 votes
by (16.8k points)
edited by

You can easily do it in one step, use the following code:

dictionary[new_key] = dictionary[old_key]

del dictionary[old_key]

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...