Checking if a string is a heterogram in Python

One line is given here, then our task is &check if the given line is heterogram or not. 

The point of checking a heterogram in Python is that a word, phrase or sentence in which no letter of the alphabet occurs more than once. A heterogram can be distinguished from a pangram, which uses all the letters of the alphabet.


< p> String is abc def write

This is Heterogram (no alphabet repeated)

String abc bcd dfh

 This is not Heterogram. (b, c, d are repeated) 


 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. 

Sample 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 :: & gt;") n = len (s) print (s, "This string is Heterogram" if stringheterogram (s, n) else "This string is not Heterogram") 


 Enter the String :: & gt; asd fgh jkl asd fgh jkl this string is Heterogram Enter the String :: & gt; asdf asryy asdf asryy This string is not Heterogram  

Get Solution for free from DataCamp guru