Preloaded translation and reduced return statement
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 Trueelse:return False- forward = s.lower().replace(" ", "").translate(trans)
- return forward == forward[::-1]