Post

PythonPython

christina joce

Posted on 27th April 2024|64 views

0
votes

Rename Dictionary Key Python

How to rename a dictionary key in python?

 

Answers
P
chris bons

Posted on 27th April 2024

I will give you an example to rename a dictionary key using a naive method there are different methods to do this but I fell naive method is very easy so have a look

ini_dict = {'Akhil': 1, 'vissu' : 5,

            'Nikita' : 10, 'deepu' : 15}

print ("initial dictionary", ini_dict)

ini_dict['Akhil'] = ini_dict['Akshay']

del ini_dict['Akshay']

print ("final dictionary", str(ini_dict))

Output:

initial dictionary{‘Akhil’:1, ‘deepu’:15, ‘vissu’:5, ‘Nikitha’:10}

final dictionary {‘Akshay’:1, ‘deepu’:15, ‘vissu’:5, ‘Nikitha’:10}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos