forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_isogram.py
More file actions
27 lines (22 loc) · 708 Bytes
/
is_isogram.py
File metadata and controls
27 lines (22 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
wiki: https://en.wikipedia.org/wiki/Heterogram_(literature)#Isograms
"""
def is_isogram(string: str) -> bool:
"""
An isogram is a word or phrase in which no letter is repeated.
Non-alphabetic characters are ignored.
>>> is_isogram('Uncopyrightable')
True
>>> is_isogram('allowance')
False
>>> is_isogram('six-year-old')
True
>>> is_isogram('copy1')
True
"""
letters = [char.lower() for char in string if char.isalpha()]
return len(letters) == len(set(letters))
if __name__ == "__main__":
input_str = input("Enter a string ").strip()
isogram = is_isogram(input_str)
print(f"{input_str} is {'an' if isogram else 'not an'} isogram.")