From the course: Python Data Structures and Algorithms
Challenge: Reverse a string using a stack - Python Tutorial
From the course: Python Data Structures and Algorithms
Challenge: Reverse a string using a stack
(upbeat music) - A stack lends itself naturally to problems where you need to reverse the order of something. In this challenge we ask you to find the hidden message by reversing a string using the stack class we just built. Template code is provided. Your task is to implement the solution. So the template code is here in reversed string dot PY. And what we've given you on line seven, we've imported the stack that we just built. Okay. And the way we create an instance of that, because it's imported on line 11, we're doing S equals stack dot stack. Notice the capitalization. Lowercase on the first one. That's the name of the module. And then capital is the name of the class within that module. One thing that's going to help you with this challenge is using a while loop combined with the is empty method from our stack class, so that you can know when there's anything in the stack. So when you've finished, that will be your way of testing whether you finished emptying the stack. So I'm going to to let you think about that. Good luck with it. This should take maybe four to five minutes possibly. And I'll show you the solution in the next video.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.