import string def cleanstring(s): """ Remove spaces and punctuation from the string. Also convert to all lower case. """ s = string.lower(s) s = string.replace(s, " ", "") s = string.replace(s, ".", "") s = string.replace(s, ",", "") return s def ispalindrome(str): """ Return true if the string is a palindrome. """ str = cleanstring(str) length = len(str) nos = 0 for pos in range(length/2): pos2 = length-pos-1 if str[pos]!=str[pos2]: # found a mismatch nos = nos + 1 if nos==0: return True else: return False str = raw_input("Enter a string: ") if ispalindrome(str): print "Yes" else: print "No"