Palindrome Checker

Function that checks if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). For example, “radar” and “level” are palindromes.

def pall(i):
b=i[ : :-1]
if b==i:
print(‘the given word is a pallindrome’)
else:
print(‘the given word is not a pallindrome’)

i=input('enter a word: ')
pall(i)
print()

1 Like

Another way to check palindrome

def palindrome(str = ''):
    rev = ''
    for char in reversed(str):
        rev += char
    if(rev == str):
        return True
    else:
        return False

I share my solution:

def is_palindrome(char_seq):
    char_seq = re.sub(r"\s+", "", char_seq) # remove tabs, newlines, and all whitespace (like \n, \t)
    char_seq = re.sub(r"[^\w\s]", "", char_seq) # strip punctuation
    char_seq = char_seq.lower() # ignore capitalization
    print(char_seq)
    while len(char_seq) != 0:
        if char_seq[0] == char_seq[-1]:
            char_seq = char_seq[1:len(char_seq)-1]
        else:
            return False
    return True