Who doesn't love making code just one line!
import string is_palindrome = lambda s: (x := s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))) == x[::-1]
- import string
def is_palindrome(s: str) -> bool:s = s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))return s == s[::-1]- is_palindrome = lambda s: (x := s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))) == x[::-1]