
- 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 given string is anagram of palindromic or not in Python
Suppose we have a string s, we have to check whether any permutation of s is a palindrome or not.
So, if the input is like s = "admma", then the output will be True, as we can rearrange "admma" to "madam" which is a palindrome.
To solve this, we will follow these steps −
- c := a map holding each individual character count of s
- count := 0
- for each i in list of all values of c, do
- if i is odd, then
- if count is same as 0, then
- count := count + 1
- come out from the loop
- return False
- if count is same as 0, then
- if i is odd, then
- return True
Let us see the following implementation to get better understanding −
Example
from collections import Counter class Solution: def solve(self, s): c = Counter(s) count = 0 for i in c.values(): if i % 2 != 0: if count == 0: count += 1 continue return False return True ob = Solution() s = "admma" print(ob.solve(s))
Input
"admma"
Output
True
- Related Articles
- Program to check given string is pangram or not in Python
- Check if any anagram of a string is palindrome or not in Python
- Python program to check whether a given string is Heterogram or not
- Python program to check if a given string is Keyword or not
- Program to check whether all palindromic substrings are of odd length or not in Python
- Program to check the string is repeating string or not in Python
- C++ program to check whether given string is bad or not
- Golang Program to check the given string is empty or not
- Python - Check if a given string is binary string or not
- Program to check a string is palindrome or not in Python
- Java program to check whether a given string is Heterogram or not
- C program to check if a given string is Keyword or not?
- C# program to check whether a given string is Heterogram or not
- Swift Program to check if a given string is Keyword or not
- Swift Program to check whether a given string is Heterogram or not

Advertisements