d = {'a':1,'b':2,'c':3,'d':4} print("Initial dictionary:",d) key=input("Enter the key to delete(a-d):") if key in d: del d[key] else: print("Key not found!") exit(0) print("Updated dictionary:",d)
OUTPUT:–
Initial dictionary: {'a': 1, 'c': 3, 'b': 2, 'd': 4} Enter the key to delete(a-d):c Updated dictionary: {'a': 1, 'b': 2, 'd': 4}