- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- if char is in char_list, then
- if char is non numeric, then
- return True
Let us see the following implementation to get better understanding −
Example
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
Advertisements