Advertisement
DanielKoehler

Untitled

Nov 13th, 2013
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 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.     onlyLetters="kayak, kayak, kayak"
  19.     if onlyLetters == "":
  20.      return False
  21.     else:
  22.         for i in onlyLetters:
  23.             letter = str.isalpha(i);
  24.             if letter == True:
  25.                     Letters += i
  26.                    
  27.  
  28.    
  29.     onlyLetters = str.isalpha(onlyLetters);
  30.     reverseLetters = Letters[::-1]
  31.     if ignorecase==False:
  32.         if reverseLetters == Letters:
  33.             return True
  34.         else:
  35.             return False
  36.  
  37.  
  38.  
  39.  
  40.     # Create an empty string "onlyLetters"
  41.     # Loop over all characters in the string argument, and add each
  42.     #   character which is a letter to "onlyletters"
  43.  
  44.     # Reverse "onlyletters" and test if this is equal to "onlyletters"
  45. print isPalindrome("kayak, kayak, kayak")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement