Python Program to Check if Key Exists in Dictionary Using Count()
# Check if a Key is Already Present in a Dictionary Python using count() # Python 3 Program to check whether the given key already exists in a dictionary. # Driver Code dic = {'a': 100, 'b': 200, 'c': 300} key = 'b' x = list(dic.keys()) res = "Not Present" if(x.count(key) == 1): res = "Present" print(res)
Output:
Present