Ad

Preloaded translation and reduced return statement

Code
Diff
  • import string
    trans = str.maketrans('', '', string.punctuation)
    def is_palindrome(s: str) -> bool:
        forward = s.lower().replace(" ", "").translate(trans)
        return forward == forward[::-1]
    • import string
    • trans = str.maketrans('', '', string.punctuation)
    • def is_palindrome(s: str) -> bool:
    • forward = s.lower().replace(" ", "").translate(str.maketrans('', '', string.punctuation))
    • reverse = forward[::-1]
    • if forward == reverse:
    • return True
    • else:
    • return False
    • forward = s.lower().replace(" ", "").translate(trans)
    • return forward == forward[::-1]