Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
21 lines (17 loc) · 392 Bytes

key-in-dict.md

File metadata and controls

21 lines (17 loc) · 392 Bytes
title type tags cover dateModified
Key in dictionary
snippet
dictionary
rocky-mountains
2020-10-16 21:30:49 +0300

Checks if the given key exists in a dictionary.

  • Use the in operator to check if d contains key.
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