Python program to delete a list of keys from a dictionary.

In this python dictionary program, we will delete a list of keys from a dictionary.

Steps to solve the program
  1. Take a dictionary and a list of keys as input.
  2. Use for loop to iterate over keys in the list.
  3. Delete the keys from the diction using del.
  4. Print the output.
				
					D1 = {'a':19,'b': 20,'c':21,'d':20,'e':50}
Key = ['a','d','e']

for key in Key:
    del D1[key]
    
print(D1)
				
			

Output :

				
					{'b': 20, 'c': 21}
				
			

initialize a dictionary with default values.

rename key of a dictionary

Leave a Comment