Learn from this video how to write the code for the suggested approach to solving the palindrome challenge.
- [Narrator] Now I'll show you the code I wrote…to solve this problem.…I knew that I had to use a deque…and I implemented the deque exactly the same way…that we did earlier in the chapter.…So I won't go through that here.…Instead I'll move on to the function itself.…I created a function on line 22 called check_palindrome.…It takes a parameter called input string…and that's the string we want to check…whether or not it's a palindrome.…On line 24 I create my own deque object called…my underscore d and for every character in my input string…I add that character to the rear of the deque.…
This preserves the order of the characters…as they are present in the input string.…On line 28 I start my while loop.…As long as there are at least two items in my deque…I want to continue removing items from each end…and comparing them.…I do that by calling the remove front method…on my deque on line 29,…and store that in a variable called front item.…And I do something very similar on line 30…where I call the remove rear method on my deque object…
Author
Released
12/6/2018- 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
Duration
Views
Related Courses
-
Learning the Python 3 Standard Library
with Kathryn Hodge2h 9m Intermediate -
Python Essential Training
with Bill Weinman4h 45m Intermediate -
Faster Python Code
with Miki Tebeka2h 4m Advanced -
Learning Python
with Joe Marini2h 27m Beginner -
Advanced Python
with Joe Marini2h 27m Advanced
-
Introduction
-
What you should know1m 26s
-
1. Abstract Data Types and Data Structures
-
Abstract data types3m 28s
-
Data structures40s
-
-
2. The Stack
-
push()3m 27s
-
pop()3m 57s
-
peek()3m 28s
-
size()1m 51s
-
is_empty()2m 13s
-
Challenge: Balanced symbols1m 10s
-
3. The Queue
-
enqueue()3m 8s
-
dequeue()3m 29s
-
peek()3m 43s
-
size() and is_empty()3m 2s
-
Challenge: Print queue1m 14s
-
Print queue solution in code4m 19s
-
4. The Deque
-
add_rear() and add_front()4m 21s
-
peek_rear() and peek_front()3m 50s
-
Conclusion
-
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.
CancelTake 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.
Share this video
Embed this video
Video: Palindrome checker solution in code