In this python dictionary program, we will delete a list of keys from a dictionary.
Steps to solve the program
- Take a dictionary and a list of keys as input.
- Use for loop to iterate over keys in the list.
- Delete the keys from the diction using del.
- 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}