Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isPalindrome(s, ignorecase=False):
- """
- >>> type(isPalindrome("bob"))
- <type 'bool'>
- >>> isPalindrome("abc")
- False
- >>> isPalindrome("bob")
- True
- >>> isPalindrome("a man a plan a canal, panama")
- True
- >>> isPalindrome("A man a plan a canal, Panama")
- False
- >>> isPalindrome("A man a plan a canal, Panama", ignorecase=True)
- True
- """
- Letters = ""
- for i in s:
- letter = str.isalpha(i);
- if letter == True:
- Letters += i
- reverseLetters = Letters[::-1]
- if reverseLetters == Letters and ignorecase == False:
- return True
- elif reverseLetters.upper() == Letters.upper() and ignorecase == True:
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement