Palindrome Check Function

  • Share this:

Code introduction


Determines if a string is a palindrome, i.e., a string that reads the same forwards and backwards.


Technology Stack : str, re, math

Code Type : Function

Code Difficulty : Intermediate


                
                    
import math
import re

def is_palindrome(s):
    if not isinstance(s, str):
        return False
    s = re.sub(r'\W+', '', s).lower()
    return s == s[::-1]                
              
Tags: