in — Intermediate Playground
Membership test operator; also used in for loops to iterate over items
Python Playground
Output
Click "Run" to execute your code'in' calls __contains__ if defined. Sets and dicts are O(1), lists are O(n). Python 3's range has O(1) membership testing. Generators are consumed during the search.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?