← Back to challenges

Does the Dictionary Contain a Given Key?

PythonMediumobjectslanguage_fundamentalsvalidation

Instructions

Write a function that returns True if a dictionary contains the specified key, and False otherwise.

Examples

has_key({ "a": 44, "b": 45, "c": 46 }, "d") ➞ False

has_key({ "craves": True, "midnight": True, "snack": True }, "morning") ➞ False

has_key({ "pot": 1, "tot": 2, "not": 3 }, "not") ➞ True

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: First Class, Second Class and Third Class Levers