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.
Nice to see this way! Good understanding classes!))
Last 'if" is obviously redundant. Check other solutions of this kind
Well, that is a massive amount of unnecessary code and comments.
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.Why not simply use list.append() and list.pop() to emulate a stack, as presented in the Python docs (5.1.1)?
lol what
we get it you know OOP :D
Overthinking...
I don't think convoluting the logic by introducing unecessary structures would be considered proper; unless you strongly suspected that you would in fact need to know what was pushed later on, and didn't want to have to make large changes later.
I would add len(self) for correctness.
But it is better to use the stack for more correct logic.
holy sh dude what lead you to this.
looks like this has been an issue for quite a long time :(
I confirm the same issue.
Loading more items...