- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a string contains a palindromic sub-string of even length in Python
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
Advertisements