Member-only story

4 Python String Manipulation Practice Exercises

Liu Zuo Lin
5 min readJul 18, 2021

--

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”

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

No responses yet