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

Browse Categories