22 lines
570 B
Python
22 lines
570 B
Python
class Phrase:
|
|
"""A class to represent phrases."""
|
|
|
|
def __init__(self, content):
|
|
self.content = content
|
|
|
|
def ispalindrome(self):
|
|
"""Return True for a palindrome, False otherwise."""
|
|
processed_content = self.content.lower()
|
|
return processed_content == reverse(processed_content)
|
|
|
|
def __iter__(self):
|
|
self.phrase_iterator = iter(self.content)
|
|
return self
|
|
|
|
def __next__(self):
|
|
return next(self.phrase_iterator)
|
|
|
|
def reverse(string):
|
|
"""Reverse a string."""
|
|
return "".join(reversed(string))
|