Check Key Membership

Easy ⏱ 8 min 79% acceptance ★★★★☆ 4.3
Write a function has_sku(inventory, sku) that returns True if sku is a key in the dict inventory, and False otherwise. Use the in operator, not .keys().

Examples

Example 1
Input
has_sku({'A1': 5, 'B2': 0}, 'B2')
Output
True
Explanation

B2 is a key, even though its value is 0.

Example 2
Input
has_sku({'A1': 5}, 'C3')
Output
False
Explanation

C3 is not a key.

Constraints

  • Membership must check keys, not values.

Topics

Dictionariesmembership

Companies

SwiggyZomato

Hints

Hint 1

`key in some_dict` checks keys directly and is O(1) on average.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.