Write a program that checks whether a given string is a palindrome, ignoring punctuation, whitespace, and letter casing.
Example:
Input: "A man, a plan, a canal: Panama"
Output: True
First, remove all punctuation and whitespace from the string and convert it to lower case. Then, compare the resulting string with its reverse to check if the input string is a palindrome.
import re
def is_palindrome(s):
s = re.sub(r'\W+', '', s).lower()
return s == s[::-1]
print(is_palindrome("A man, a plan, a canal: Panama")) # Outputs: True
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.