Search This Blog

Python: test if a dictionary contains a specific key



def contains(dict, key):
return key in dict

dict={}
dict['a']=1
dict['b']=2
dict['c']=3

print(contains(dict, 'a')) # True
print(contains(dict, 'd')) # False

No comments:

Post a Comment