Suppose we have a string s. We have to check whether this string contains some even length palindrome or not.
So, if the input is like s = "afternoon", then the output will be True as "afternoon" has even length palindrome "noon".
To solve this, we will follow these steps:
- for i in range 0 to size of string - 1, do
- if string[i] is same as string[i + 1], then
- return True
- if string[i] is same as string[i + 1], then
- return False
Let us see the following implementation to get better understanding −
Example
def solve(string): for i in range (0, len(string)): if (string[i] == string[i + 1]): return True return False s = "afternoon" print(solve(s))
Input
"afternoon"
Output
True