<p>A phrase is a <strong>palindrome</strong> if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.</p>

<p>Given a string <code>s</code>, return <code>true</code><em> if it is a <strong>palindrome</strong>, or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;A man, a plan, a canal: Panama&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> &quot;amanaplanacanalpanama&quot; is a palindrome.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;race a car&quot;
<strong>Output:</strong> false
<strong>Explanation:</strong> &quot;raceacar&quot; is not a palindrome.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot; &quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> s is an empty string &quot;&quot; after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 2 * 10<sup>5</sup></code></li>
	<li><code>s</code> consists only of printable ASCII characters.</li>
</ul>

import math
import re

class Solution:
    def isPalindrome(self, s: str) -> bool:
        # Convert to lowercase and remove non-alphanumeric characters
        low_str = s.lower()
        str_trunk = re.sub(r'[^a-zA-Z0-9]', '', low_str)

        l_chars = [*str_trunk]
        len_char = len(l_chars)
        print(l_chars, len_char)

        first_half = []
        second_half = []

        for i, char in enumerate(l_chars):
            # Compute the middle index for even and odd length cases
            mid = len_char // 2

            # For even length, split exactly in the middle
            if len_char % 2 == 0:
                if i < mid:
                    first_half.append(char)
                if i >= mid:
                    second_half.insert(0, char)
            # For odd length, split around the middle character
            else:
                if i < mid:
                    first_half.append(char)
                if i > mid:
                    second_half.insert(0, char)

        print(first_half, second_half)
        if first_half == second_half:
            print("true")
            return True
        else:
            return False

19600