How can I implement a custom stack data structure with dynamic resizing in Python?
I’m trying to implement my own Stack class in Python. I want the stack to have dynamic resizing capabilities, similar to how Python’s lists automatically grow when needed. Specifically, when the stack reaches its current capacity, it should double in size, and when it shrinks below a certain threshold, it should reduce its size to save memory. How can I efficiently implement this dynamic resizing in a stack data structure? What are the best practices to follow?