Member-only story
4 Python String Manipulation Practice Exercises
As a Python Tutor who often prepares students for University level Python programming tests, I often find myself explaining the same solution to multiple practice questions to multiple different students.
As such, I’ve compiled a couple of common practice questions as well as the solutions and explanations in this article, and hopefully you find some value out of it!
Questions
Palindrome Phrases
A palindrome phrase is a phrase that read the same backward as forward (ignoring casing and whitespaces). Some examples of palindromes:
- civic
- level
- Was it a car or a cat I saw
- Mr Owl ate my metal worm
Write a function is_palindrome_phrase that takes in a string and returns True if the string is a palindrome and False otherwise. (Remember to ignore whitespaces and casing)
Anagrams
2 words are anagrams if one can be formed by rearranging the letters of another and using each letter ONCE (whitespaces and casing are ignored here). Some examples of anagrams:
- “tar” & “rat”
- “binary” & “brainy”
- “Astronomer” & “Moon Starer”