python if exist in dictionary code example
Example 1: python how to check if a dictionary key exists
if word in data:
return data[word]
else:
return "The word doesn't exist. Please double check it."
Example 2: python test if list of dicts has key
>>> lod = [{1: "a"}, {2: "b"}]
>>> any(1 in d for d in lod)
True
>>> any(3 in d for d in lod)
False