Support the in Operator

Easy ⏱ 8 min 89% acceptance ★★★★★ 4.5
Build Inventory initialized with a list of SKUs, implementing __contains__ (case-insensitive) so 'ABC' in inv works naturally. Store the SKUs lowercased in a set internally for O(1) checks.

Examples

Example 1
Input
inv = Inventory(['Pen', 'Ink']); 'PEN' in inv
Output
True
Explanation

Membership is case-insensitive via the dunder.

Constraints

  • Implement __contains__.
  • Internal storage is a lowercase set.

Topics

OOP__contains__

Companies

FlipkartWalmartMyntra

Hints

Hint 1

__contains__(self, item) receives the left operand of in.

Hint 2

Lowercase both sides.

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