Suppose we have a string s, we have to check whether the string palindromes as its prefix and suffix substrings or not.
So, if the input is like s = "levelishighforracecar", then the output will be True as there are palindrome prefix and suffix: "level" and "racecar" respectively.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def is_palindrome(s): return s == s[::-1] def solve(s): l = len(s) for i in range(2, l + 1): if is_palindrome(s[0:i]): break if i == (l + 1): return False for i in range(2, l + 1): if is_palindrome(s[l - i : l]): return True return False s = "levelishighforracecar" print(solve(s))