Posted on 22nd July 2024|64 views
How to rename a dictionary key in python?
Posted on 22nd July 2024| views
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}