Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Which Implementation Should You Use?

In this lesson, you’ll cover which implementation you should use for a Python stack in various contexts. You’ll also follow a run-through in the terminal to get a practical idea of what to consider if you want to use these implementations in your code.

Download

Sample Code (.py)

1.7 KB

Download

Course Slides (.pdf)

302.5 KB

Max on March 4, 2020

Nicely done, to the point, no overhead. Just perfect to start off my working day :)

rolandgarceau on March 4, 2020

Can you give examples for the last few seconds of the video when you mentioned we need to add in checks?

Liam Pulsifer RP Team on March 4, 2020

@rolandgarceau sure, happy to! I’m guessing you mean when I say you should implement checks to avoid errors caused by popping from an empty stack? If not, feel free to drop another comment and clarify what you’re looking for, but here goes:

while my_list: # Assuming a list-based stack implementation called "my_list"
    my_list.pop()

while my_deque: # Deque version
    my_deque.pop()

while not my_stack.empty(): # with LifoQueue 
    my_stack.get()

DanielHao5 on March 7, 2020

Good Intro to the stack. It would be great to elaborate more on the Use Cases for different scenarios, eg. is_valid_brackets(), type of questions.

Thanks. Daniel

Lee Crampton on March 8, 2020

Nice and concise. Thanks.

patientwriter on April 5, 2020

If you are not interested in a stack, is LifoQueue() still the way to go for thread safety?

Liam Pulsifer RP Team on April 5, 2020

@patientwriter the queue module is definitely still the right place to go if you need thread safety as well as some sort of queue-like behavior because all of the functions and objects in that module are written with thread safety in mind, but of course you might not always need the LIFO behavior that queue.LifoQueue gives you, so it’s worth reading through the documentation to see what (if anything) in that module fits your needs.

Soumya Ranjan Sahu on June 7, 2020

Thanks Liam! It was a very informative session.

TheManWhoSoldTheWorld on June 12, 2020

I really like to learn about LifoQueue(). Thanks Liam, nice videos.

Become a Member to join the conversation.