

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 is Colindrome in Python
Suppose we have a string s. We have to check whether the given string is colindrome or not. The colindrome is a concatenated string of 6 length palindromes.
So, if the input is like s = "aabbaamnoonm", then the output will be True as this contains palindromes like "aabbaa" and "mnoonm", both are of length 6.
To solve this, we will follow these steps −
- if size of s is not multiple of 6, then
- return False
- for i in range 0 to size of s - 1, increase by 6, do
- if s[from index i to i+5] is not palindrome, then
- return False
- if s[from index i to i+5] is not palindrome, then
- return True
Let us see the following implementation to get better understanding −
Example
def is_palindrome(s): return s == s[::-1] def solve(s): if len(s) % 6 != 0: return False for i in range(0, len(s), 6): if not is_palindrome(s[i : i+6]): return False return True s = "aabbaamnoonm" print(solve(s))
Input
"aabbaamnoonm"
Output
True
- Related Questions & Answers
- Python - Check if a variable is string
- Check if a string is Pangrammatic Lipogram in Python
- Python - Check if a given string is binary string or not
- How to check if a string is alphanumeric in Python?
- Check if a string is Isogram or not in Python
- Check if a string is suffix of another in Python
- Check if a given string is a valid number in Python
- How to check if a string in Python is in ASCII?
- Check if a string is sorted in JavaScript
- How to check if a string is a valid keyword in Python?
- Check if a given string is sum-string in C++
- Python program to check if a string is palindrome or not
- Python program to check if a given string is number Palindrome
- Python program to check if the string is pangram
- How to check if type of a variable is string in Python?
Advertisements