This:
def pop(self) -> tuple[Any, Stack]:
"""Pops from the stack, returning an (elem, updated stack) pair."""
What is the reason behind returning updated stack along with top element from pop()
method?
From the docstring of the Stack
class: "A bounded functional stack implementation."
A functional implementation generally means that pure functions are used.
The pop
function implements two pure function properties:
This is why it must return a (mutated) copy of the input Stack
instead of modifying it.