Home » isogram checker in python

isogram checker in python

1 Year Subscription
Java SE 11 Developer (Upgrade) [1Z0-817]
Java SE 11 Programmer II [1Z0-816] Practice Tests
Spring Framework Basics Video Course
Java SE 11 Programmer I [1Z0-815] Practice Tests
Oracle Java Certification

A heterogram is a word, phrase, or sentence in which no letter of the alphabet occurs more than once.

The terms isogram and nonpattern word have also been used to mean the same thing

Isogram has also been used to mean a string where each letter present is used the same number of times. Multiple terms have been used to describe words where each letter used appears a certain number of times.

For example, a word where every featured letter appears twice, like “appeases”, might be called a pair isogram, a second-order isogram, or a 2-isogram.

A perfect pangram is an example of a heterogram, with the added restriction that it uses all the letters of the alphabet.

Code Examples

def isogram_checker(word):
    # Convert to lower case
    clean_word = word.lower()
    # Make a list for unique letters
    letter_list = []
    for letter in clean_word:
        if letter.isalpha():
            if letter in letter_list:
                return False
            letter_list.append(letter)
    return True

print(isogram_checker("test"))
print(isogram_checker("python"))
print(isogram_checker("maxpython.com"))

 

def is_isogram(string):
    # if not a Str then return False
    if type(string) is not str:
        return False
    
    # if empty then return True
    if len(string)==0:
        return True
    
    # store characters
    db = set()
    
    # loop through the string, but lowercase it first
    for char in string.lower():
        # if it's already been seen, then return False
        if char in db:
            return False
        else:
            # otherwise add to the db
            db.append(char)
            
    # return True if not failed
    return True

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More