Advertisement
DanielKoehler

Untitled

Nov 13th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def isPalindrome(s, ignorecase=False):
  2.    
  3.     """
  4.     >>> type(isPalindrome("bob"))
  5.     <type 'bool'>
  6.     >>> isPalindrome("abc")
  7.     False
  8.     >>> isPalindrome("bob")
  9.     True
  10.     >>> isPalindrome("a man a plan a canal, panama")
  11.     True
  12.     >>> isPalindrome("A man a plan a canal, Panama")
  13.     False
  14.     >>> isPalindrome("A man a plan a canal, Panama", ignorecase=True)
  15.     True
  16.     """
  17.     Letters = ""
  18.     for i in s:
  19.         letter = str.isalpha(i);
  20.         if letter == True:
  21.                 Letters += i
  22.                  
  23.     reverseLetters = Letters[::-1]
  24.     if ignorecase==False:
  25.         if reverseLetters == Letters:
  26.             return True
  27.         else:
  28.             return False
  29.  
  30.  
  31.  
  32.  
  33.     # Create an empty string "onlyLetters"
  34.     # Loop over all characters in the string argument, and add each
  35.     #   character which is a letter to "onlyletters"
  36.  
  37.     # Reverse "onlyletters" and test if this is equal to "onlyletters"
  38. print isPalindrome("kayak, kayak, kayak")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement