In python I need a stack, and I'm using a list for it. In the documenation it says that you can use append() and pop() for stack operations but what about accessing the top of the stack without removing it?
How to do that in the most readable way? Because all I came up with is stack[-1:][0]
which looks a bit ugly for me, there must be a better way.
No need to slice.
stack[-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With