MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __contains__

Method __contains__

data_structures/stacks/stack.py:144–158  ·  view source on GitHub ↗

Check if item is in stack >>> S = Stack(3) >>> S.push(10) >>> 10 in S True >>> S = Stack(3) >>> S.push(10) >>> 20 in S False

(self, item: T)

Source from the content-addressed store, hash-verified

142 return len(self.stack)
143
144 def __contains__(self, item: T) -> bool:
145 """
146 Check if item is in stack
147
148 >>> S = Stack(3)
149 >>> S.push(10)
150 >>> 10 in S
151 True
152
153 >>> S = Stack(3)
154 >>> S.push(10)
155 >>> 20 in S
156 False
157 """
158 return item in self.stack
159
160
161def test_stack() -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected