Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion data_structures/stacks/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def is_empty(self):
def size(self):
""" Return the size of the stack."""
return len(self.stack)


def __contains__(self, item) -> bool:
"""Check if item is in stack"""
return item in self.stack


class StackOverflowError(BaseException):
pass
Expand All @@ -66,3 +70,7 @@ class StackOverflowError(BaseException):
print("After push(100), the stack is now: " + str(stack))
print("is_empty(): " + str(stack.is_empty()))
print("size(): " + str(stack.size()))
num = 5
if num in stack:
print(f"{num} is in stack")