2022-11-13 10:39:28 -08:00

25 lines
645 B
Python

import re
class Phrase:
"""A class to represent phrases."""
def __init__(self, content):
self.content = content
def ispalindrome(self):
"""Return True for a palindrome, False otherwise."""
return self.processed_content() == reverse(self.processed_content())
def processed_content(self):
"""Return content for palindrome testing."""
return self.letters().lower()
def letters(self):
"""Return the letters in the content."""
return "".join(re.findall(r"[a-zA-Z]", self.content))
def reverse(string):
"""Reverse a string."""
return "".join(reversed(string))