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 = ""
- onlyLetters="kayak, kayak, kayak"
- if onlyLetters == "":
- return False
- else:
- for i in onlyLetters:
- letter = str.isalpha(i);
- if letter == True:
- Letters += i
- onlyLetters = str.isalpha(onlyLetters);
- reverseLetters = Letters[::-1]
- if ignorecase==False:
- if reverseLetters == Letters:
- return True
- else:
- return False
- # Create an empty string "onlyLetters"
- # Loop over all characters in the string argument, and add each
- # character which is a letter to "onlyletters"
- # Reverse "onlyletters" and test if this is equal to "onlyletters"
- print isPalindrome("kayak, kayak, kayak")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement