
- 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
Python program to check whether a given string is Heterogram or not
Here one string is given then our task is to check weather a given string is Heterogram or not.
The meaning of heterogram checking is that a word, phrase, or sentence in which no letter of the alphabet occurs more than once. A heterogram may be distinguished from a pangram which uses all of the letters of the alphabet.
Example
String is abc def ghi
This is Heterogram (no alphabet repeated)
String is abc bcd dfh
This is not Heterogram. (b,c,d are repeated)
Algorithm
Step 1: first we separate out list of all alphabets present in sentence. Step 2: Convert list of alphabets into set because set contains unique values. Step 3: if length of set is equal to number of alphabets that means each alphabet occurred once then sentence is heterogram, otherwise not.
Example Code
def stringheterogram(s, n): hash = [0] * 26 for i in range(n): if s[i] != ' ': if hash[ord(s[i]) - ord('a')] == 0: hash[ord(s[i]) - ord('a')] = 1 else: return False return True # Driven Code s = input("Enter the String ::>") n = len(s) print(s,"This string is Heterogram" if stringheterogram(s, n) else "This string is not Heterogram")
Output
Enter the String ::> asd fgh jkl asd fgh jkl this string is Heterogram Enter the String ::>asdf asryy asdf asryy This string is not Heterogram
- Related Articles
- Java program to check whether a given string is Heterogram or not
- C# program to check whether a given string is Heterogram or not
- Swift Program to check whether a given string is Heterogram or not
- C++ program to check whether given string is bad or not
- Program to check whether given graph is bipartite or not in Python
- Python program to check if a given string is Keyword or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Program to check given string is pangram or not in Python
- Program to check whether given matrix is Toeplitz Matrix or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Program to check whether given tree is symmetric tree or not in Python
- Python program to check whether a list is empty or not?
- How to Check Whether a String is Palindrome or Not using Python?
- Program to check whether given password meets criteria or not in Python
- C++ Program to check whether given password is strong or not

Advertisements