Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions strings/is_isogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@

def is_isogram(string: str) -> bool:
"""
An isogram is a word in which no letter is repeated.
Examples of isograms are uncopyrightable and ambidextrously.
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')
Traceback (most recent call last):
...
ValueError: String must only contain alphabetic characters.
True
"""
if not all(x.isalpha() for x in string):
raise ValueError("String must only contain alphabetic characters.")

letters = sorted(string.lower())
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.")
Loading