Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_palindrome(word):
- """(str) -> bool
- Precondition: word.isalpha and word.islower hold True
- Return True iff word is palindrome
- >>>is_palindrome('radar'):
- True
- >>>is_palindrome('cats'):
- False
- >>>is_palindrome('toot'):
- True
- """
- i = 0
- while i <= (len(word))//2:
- j = -(i+1)
- if word[i] == word[j]:
- i = i+1
- else:
- return False
- return True
- def is_palindromic_phrase(phrase):
- """
- (str) -> bool
- Precondition: if apostrophe used ensure that the different one is to denote that the phrase is a string
- Return True iff phrase, regardless of case and non-alphabetic characters,
- is a palindrome
- >>>is_palindromic_phrase("Madam, I'm Adam"):
- True
- >>>is_palindromic_phrase('Hello world!'):
- False
- >>>is_palindromic_phrase('3 nurses run'):
- True
- """
- for ch in phrase:
- if not ch.isalpha():
- phrase = phrase.replace(ch, '')
- phrase = phrase.lower()
- return is_palindrome(phrase)
- def get_odd_palindrome_at():
- """
- (str, int) -> str
- >>>get_odd_palindrome_at('fadar',2)
- ada
- >>>get_odd_palindrome_at('statistics',2)
- tat
- >>>get_odd_palindrome_at('word',3)
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement