We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 853741e commit b6fcee3Copy full SHA for b6fcee3
data_structures/stacks/stack.py
@@ -46,7 +46,11 @@ def is_empty(self):
46
def size(self):
47
""" Return the size of the stack."""
48
return len(self.stack)
49
-
+
50
+ def __contains__(self, item) -> bool:
51
+ """Check if item is in stack"""
52
+ return item in self.stack
53
54
55
class StackOverflowError(BaseException):
56
pass
@@ -66,3 +70,7 @@ class StackOverflowError(BaseException):
66
70
print("After push(100), the stack is now: " + str(stack))
67
71
print("is_empty(): " + str(stack.is_empty()))
68
72
print("size(): " + str(stack.size()))
73
+ num = 5
74
+ if num in stack:
75
+ print(f"{num} is in stack")
76
0 commit comments