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.

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

Comments & Discussion

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.

Become a Member to join the conversation.