
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
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 Articles
- Python - Check if a variable is string
- Check if a string is Pangrammatic Lipogram in Python
- 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
- Python - Check if a given string is binary string or not
- Check if a given string is a valid number in Python
- How to check if a string in Python is in ASCII?
- How to check if a string is a valid keyword in Python?
- How to check if type of a variable is string in Python?
- How to check if a character in a string is a letter in Python?
- Python Program to check if a substring is present in a given string.
- Python program to check if a string is palindrome or not
- Python program to check if a given string is number Palindrome
- How to check if a substring is contained in another string in Python

Advertisements