diff --git a/strings/is_isogram.py b/strings/is_isogram.py index a9d9acc8138e..39ba62d936b5 100644 --- a/strings/is_isogram.py +++ b/strings/is_isogram.py @@ -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.")