Python program to rename key of a dictionary

In this python dictionary program, we will rename key of a dictionary

Steps to solve the program
  1. Take a dictionary as input.
  2. Add a new key and assign its value to the previous key using pop().
  3. In this way, we will rename the key for that value.
  4. Print the output.
				
					D1 = {'a':19,'b': 20,'c':21,'d':20}
D1['e'] = D1.pop('d')
        
print(D1)
				
			

Output :

				
					{'a': 19, 'b': 20, 'c': 21, 'e': 20}
				
			

delete a list of keys from a dictionary.

Invert a given dictionary with non-unique hashable values.

Leave a Comment