Picture a pile of dishes: you add and remove dishes only at the top. A stack’s pop operation removes and returns its most recently added element, following LIFO order. section 8.3
Pop works with push to form a stack’s core interface. It returns the top element while removing it; peek, when available, reads the top without removal. section 8.19 section 8.3
Popping from a stack
If a stack contains elements in insertion order, pop removes the element at the top—the one added most recently. Calling pop on an empty stack raises a clear ValueError instead of exposing a linked-list error. section 8.11 section 8.3
def pop(self):
if self.is_empty():
raise ValueError("Cannot pop from an empty stack")
return self._data.delete_from_front()
This implementation checks for an empty stack, raises a stack-level error, and delegates removal to the underlying linked list. section 8.11
A stack can store elements in an array or linked list. Dynamic arrays provide O(1) amortized pop performance, while singly linked lists provide O(1) worst-case performance. section 8.19 section 8.9



