This page is the module index for stacks.
This legacy page is the implementation inventory. Start with stack basics, then choose monotonic stack patterns or stack parsing and expressions for focused overviews.
stacks/stack.py— bounded stack: capacity, decorator guards, amortized O(1)push, O(1)popandpeek.stacks/stack.py—Stack(limit=None)is the unbounded stack used by algorithm lessons. The default limit stays 10.stacks/symbol_balance.py— one pass. O(n) time, O(n) worst extra memory for openers.stacks/min_stack.py— second stack of minima.push,pop, andminimumare O(1).stacks/next_greater.py— monotonic stack. O(n) time, O(n) extra memory.stacks/stock_span.py— same monotonic pattern. O(n) time.stacks/largest_rectangle.py— histogram rectangle. O(n) time.stacks/infix_postfix.py— shunting yard plus postfix evaluation. O(n) time.stacks/sort_stack.py— one extra unbounded stack. Worst case O(n²) time, O(n) extra memory.
Industry
A working engineer uses a Python list as a stack. The language tutorial
says to add with append and to retrieve with pop() and no index, so the
last item added is the first retrieved. The time-complexity documentation
lists an end append and an end pop as amortized O(1).