1def is_palindrome(s):2    l = 03    r = len(s) - 14    while l < r:5        while l < r and not is_alpha_num(s[l]):6            l += 17        while r > l and not is_alpha_num(s[r]):8            r -= 19        if s[l].lower() != s[r].lower():10            return False11        l += 112        r -= 113    return True141516def is_alpha_num(c):17    return (18        ord('A') <= ord(c) <= ord('Z')19        or ord('a') <= ord(c) <= ord('z')20        or ord('0') <= ord(c) <= ord('9')21    )