_stack.py 351 B

12345678910111213141516
  1. from typing import List, TypeVar
  2. T = TypeVar("T")
  3. class Stack(List[T]):
  4. """A small shim over builtin list."""
  5. @property
  6. def top(self) -> T:
  7. """Get top of stack."""
  8. return self[-1]
  9. def push(self, item: T) -> None:
  10. """Push an item on to the stack (append in stack nomenclature)."""
  11. self.append(item)