Learn from this video how to write the code for the suggested approach to solving the balanced symbols challenge.
- [Instructor] Here's the code I wrote…to approach this solution.…I knew that I would have to use a stack class,…exactly as we have earlier in the course.…So I simply duplicated that code.…I won't spend any time going through it here.…Instead, I'll move on straight to the logic.…I created a function called match symbols,…which takes a parameter called symbols string.…Within this function, on line 18,…I created a dictionary called symbol pairs.…All of the keys are strings that have…one character inside of them,…and these are all of the opening symbols.…
Each of these opening symbols is mapped to a value,…which is a string containing its matching closing symbol.…On line 24, I created a variable called openers,…because I knew later on in my code,…I was going to need to check if each symbol…was an opening symbol or not.…To create the openers variable,…I simply called the dictionary's built-in keys method…on my dictionary.…I did that because all of the keys…are all of the opening symbols.…
On line 25, I instantiated my stack object…
- Abstract types and data structures
- Stacks as a linear abstract data type
- Creating the Stack class and its methods
- Adding items to the top and bottom of a stack
- Creating the Queue class and its methods
- Manipulating items in a queue
- Creating the Dequeue class and its methods
- Adding and removing items from a dequeue
Skill Level Advanced
Learning the Python 3 Standard Librarywith Kathryn Hodge2h 10m Intermediate
What you should know1m 26s
1. Abstract Data Types and Data Structures
2. The Stack
3. The Queue
4. The Deque
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.