Quick actions

cmd+k|ctrl+k

Navigation

Languages

Palindrome

Snippet info

Language

Python

Visibility

public

Author

tutor.the.code

Created

2017-08-03T13:23:19Z

Updated

2017-08-03T13:23:19Z

## is palindrome
from string import whitespace, punctuation

NON_ALPHANUM: str = whitespace + punctuation 

def is_palindrome(sentence: str) -> bool:
    sen = "".join(
        ch.lower() for ch in sentence if ch not in  NON_ALPHANUM)
    return sen == "".join(reversed(sen))
    
##test
if __name__ == '__main__':
    test = ["Ah, Satan sees Natasha!",
            "Are Mac 'n' Oliver ever evil on camera?",
            "Python"]
            
    for s in test:
        print(f"{s}. Palindrome: {is_palindrome(s)}")
    
    
        
    
INFO