In this python dictionary program, we will remove a key from the dictionary.
Steps to solve the program
- Take a dictionary as input.
- Using an if-else statement remove the given key from the dictionary.
- Print the output.
dict1 = {'a':2,'b':4,'c':5}
dict2={}
for key,val in dict1.items():
if key != "c":
dict2[key]=val
print(dict2)
Output :
{'a': 2, 'b': 4}