Write a python program to check if a given key already exists in a dictionary if the key exists replace another key/value pair
Slip 3 Q 1
CODE :
Dict={}
n=int(input('enter number of keys :'))
for x in range(0,n):
key=input('enter the key :')
if key in Dict:
print('the given key exists!')
for key in Dict.keys():
print(key,end=' ')
print('\n ^ use differnt keys from above list')
key=input('enter the key :')
value=input('enter the value :')
Dict[key]=value
print(Dict)
This comment has been removed by the author.
ReplyDelete