To find if a palindrome is valid, we can filter out any characters and then check if forwards and backwards it is the same up to the halfway point.
class Solution:
def isPalindrome(self, s: str) -> bool:
converted = [c.lower() for c in s if c.isalnum()]
mid = len(converted) // 2
if len(converted) % 2 == 0:
forwards = converted[:mid]
else:
forwards = converted[:mid+1]
backwards = converted[mid:][::-1]
return forwards == backwards