given a string determine if it is a palindrome considering only alphanumeric characters and ignoring cases for example a man a plan a canal panama is a palindrome race a car is not a palindrome note have you consider that the string might be empty this is a good question to ask during an interview for the purpose of this problem we define empty string as valid palindrome type s str rtype bool here is a bunch of other variations of ispalindrome function variation 1 find the reverse of the string and compare it with the original string variation 2 loop from the start to length2 and check the first character and last character and so on for instance s0 compared with sn1 s1 sn2 variation 3 using stack idea note we are assuming that we are just checking a one word string to check if a complete sentence remove punctuation case sensitivity and spaces variation 1 can also get rid of the stringreverse function and just do this return s s 1 in one line variation 2 variation 3 variation 4 using deque type s str rtype bool here is a bunch of other variations of is_palindrome function variation 1 find the reverse of the string and compare it with the original string variation 2 loop from the start to length 2 and check the first character and last character and so on for instance s 0 compared with s n 1 s 1 s n 2 variation 3 using stack idea note we are assuming that we are just checking a one word string to check if a complete sentence remove punctuation case sensitivity and spaces variation 1 can also get rid of the string_reverse function and just do this return s s 1 in one line variation 2 variation 3 variation 4 using deque
from string import ascii_letters
from collections import deque


def is_palindrome(s):
    
    i = 0
    j = len(s)-1
    while i < j:
        while not s[i].isalnum():
            i += 1
        while not s[j].isalnum():
            j -= 1
        if s[i].lower() != s[j].lower():
            return False
        i, j = i+1, j-1
    return True

  
def remove_punctuation(s):
    
    return "".join(i.lower() for i in s if i in ascii_letters)


def string_reverse(s):
	return s[::-1]

def is_palindrome_reverse(s):
	s = remove_punctuation(s)
	
	
	if (s == string_reverse(s)): 
		return True
	return False	



def is_palindrome_two_pointer(s):
    s = remove_punctuation(s)
	
    for i in range(0, len(s)//2):
        if (s[i] != s[len(s) - i - 1]):
            return False
    return True
	


def is_palindrome_stack(s):
    stack = []
    s = remove_punctuation(s)
	
    for i in range(len(s)//2, len(s)):
        stack.append(s[i])
    for i in range(0, len(s)//2):
        if s[i] != stack.pop():
            return False
    return True	


def is_palindrome_deque(s):
    s = remove_punctuation(s)
    deq = deque()
    for char in s:
        deq.appendleft(char)

    equal = True

    while len(deq) > 1 and equal:
        first = deq.pop()
        last = deq.popleft()
        if first != last :
            equal = False

    return equal