Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.
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. Andsize
is unidiomatic in Python,__len__
should be used.