Algorithms - Palindrome (palindrome)

# 10-palindrome.py 

Import String 

DEF is_palindrome (text: STR) -> BOOL:
     ' whether a palindrome ' 
    # 1, to remove punctuation and spaces, and all lowercase letters 
    Result = '' 
    for I in Range ( len (text)):
         iF  Not text [I] in string.punctuation + '  ' :     
            Result + = text [I] .lower ()
     Print (Result) 

    # 2, determines whether palindromic 
    n-= len (Result)
     for i in the Range (len (the Result) // 2 ):
        if result[i] != result[n-i-1]:
            return False
    return True


if __name__ == '__main__':
    print(is_palindrome('I prefer pi.'))
    print(is_palindrome('A man, a plan, a canal: Panama.'))
    print(is_palindrome('Resistance is futile!'))
    

 

Guess you like

Origin www.cnblogs.com/noonjuan/p/11407841.html