In the flavor of the work begun there, continue to modify the is_pal_phrase function to work for palindromic phrases and sentences by having it ignore spaces ignore case (upper versus lower) ignore common punctuation, that is the thirteen characters , ; : - ' " . ? ! ( ) [ ]
Problem 7.1: Phinding Palindromic Phrases
Purpose: Learn string manipulation in the context of a simple program.
For this problem, you will modify an existing program to be more flexible.
Go to your copy of CheckPalindromicPhrase.ipynb from Lab Assignment 7.
In the flavor of the work begun there, continue to modify the is_pal_phrase function to work for palindromic phrases and sentences by having it
- ignore spaces
- ignore case (upper versus lower)
- ignore common punctuation, that is the thirteen characters , ; : - ' " . ? ! ( ) [ ]
For example, "a Toyota" and "Madam, I'm Adam." and "Was it a rat I saw?" should be identified as palindromes; ditto for "A man, a plan, a canal--Panama!" and "Madam (in Eden), I'm Adam."
Comment every line you added, using the following format:
# YOURINITIALS: your comment
For example, here is a line from my function using one of the lines suggested in LA7:
s = s.replace(" ","") # MSB: remove spaces from string
A good plan of attack would be to add a line, comment it as to what it is doing, test it against the positive_test_cases by running the third block, debug, repeat.
Next, IF THEY ARE NOT ALREADY THERE add two more tests to positive_test_cases for the phrases highlighted in blue above.
Turn-In: Cut-and-paste of (1) just your commented is_pal_phrase function (2) just the output of the 25 positive test cases.
CheckPalindromicPhrase.ipynb from Lab Assignment 7 has been copied below:-
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images