title | type | tags | cover | dateModified | |
---|---|---|---|---|---|
Key in dictionary |
snippet |
|
rocky-mountains |
2020-10-16 21:30:49 +0300 |
Checks if the given key exists in a dictionary.
- Use the
in
operator to check ifd
containskey
.
def key_in_dict(d, key):
return (key in d)
d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}
key_in_dict(d, 'three') # True