Skip to content

Instantly share code, notes, and snippets.

@tusharsadhwani
Created May 5, 2021 16:36
from typing import List
class Stack:
def __init__(self) -> None:
self._values: List[int] = []
def __repr__(self) -> str:
return f'Stack{self._values!r}'
def push(self, value: int) -> None:
self._values.append(value)
def pop(self) -> int:
if len(self._values) == 0:
raise RuntimeError('Underflow!')
return self._values.pop()
stack = Stack()
print(stack) # Stack[]
stack.push(2)
stack.push(10)
print(stack) # Stack[2, 10]
print(stack.pop()) # 10
print(stack) # Stack[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment