Ad
  • Default User Avatar

    This kata is a exact problem in the stacks chapter of https://runestone.academy/ns/books/published/pythonds3/index.html. I also used this kata to memorize the book's stack class implementation.

  • Custom User Avatar

    If you look at their Stack() implementation, that is exactly what they're doing, just wrapped in their own class. For no good reason (unless they are what is typically referred to as a "corporate coder", then this is par for the course). Of course, they might have just wanted to do this as an excercise.
    As mentioned below, stacks are completely unnecessary in this context and only add extra space complexity.
    Also, peek() will crash on an empty stack, though fortunately it is never actually used. And size is unidiomatic in Python, __len__ should be used.

  • Custom User Avatar

    Why not simply use list.append() and list.pop() to emulate a stack, as presented in the Python docs (5.1.1)?