
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to check whether all palindromic substrings are of odd length or not in Python
Suppose we have a string s, we have to check whether all its palindromic substrings have odd lengths or not.
So, if the input is like s = "level", then the output will be True
To solve this, we will follow these steps −
- for i in range 1 to size of s, do
- if s[i] is same as s[i - 1], then
- return False
- if s[i] is same as s[i - 1], then
- return True
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s): for i in range(1, len(s)): if s[i] == s[i - 1]: return False return True ob = Solution() s = "level" print(ob.solve(s))
Input
"level"
Output
True
- Related Articles
- Program to check whether odd length cycle is in a graph or not in Python
- Program to check whether all leaves are at same level or not in Python
- Count all Prime Length Palindromic Substrings in C++
- Check if all the palindromic sub-strings are of odd lengths in Python
- Program to check given string is anagram of palindromic or not in Python
- Program to check whether parentheses are balanced or not in Python
- Program to check whether we can take all courses or not in Python
- Program to check whether we can unlock all rooms or not in python
- Program to check whether all can get a seat or not in Python
- Program to count number of palindromic substrings in Python
- Program to check whether elements frequencies are even or not in Python
- Program to check whether two sentences are similar or not in Python
- Check whether the length of given linked list is Even or Odd in Python
- Program to check whether two string arrays are equivalent or not in Python
- Palindromic Substrings in Python

Advertisements