Check if a string is Isogram or not in Python


Suppose we have a string s. We have to check whether the given string is isogram or not. The isogram is a string where the occurrence of each letter is exactly one.

So, if the input is like s = "education", then the output will be True because all characters in "education" occurs exactly once.

To solve this, we will follow these steps −

  • char_list := a new list
  • for each char in word, do
    • if char is non numeric, then
      • if char is in char_list, then
        • return False
      • insert char at the end of char_list
  • return True

Let us see the following implementation to get better understanding −

Example

 Live Demo

def solve(word):
   char_list = []
   for char in word:
      if char.isalpha():
         if char in char_list:
            return False
            char_list.append(char)
   return True
s = "education"
print(solve(s))

Input

"education"

Output

True

Updated on: 29-Dec-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements