Skip to content

Home

Key in dictionary

Checks if the given key exists in a dictionary.

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

More like this

Start typing a keyphrase to see matching snippets.