Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...