An isogram is a word in which no letter is repeated. Examples of isograms are uncopyrightable and ambidextrously. >>> is_isogram('Uncopyrightable') True >>> is_isogram('allowance') False >>> is_isogram('copy1') Traceback (most recent call last): ... ValueErr
(string: str)
| 4 | |
| 5 | |
| 6 | def is_isogram(string: str) -> bool: |
| 7 | """ |
| 8 | An isogram is a word in which no letter is repeated. |
| 9 | Examples of isograms are uncopyrightable and ambidextrously. |
| 10 | >>> is_isogram('Uncopyrightable') |
| 11 | True |
| 12 | >>> is_isogram('allowance') |
| 13 | False |
| 14 | >>> is_isogram('copy1') |
| 15 | Traceback (most recent call last): |
| 16 | ... |
| 17 | ValueError: String must only contain alphabetic characters. |
| 18 | """ |
| 19 | if not all(x.isalpha() for x in string): |
| 20 | raise ValueError("String must only contain alphabetic characters.") |
| 21 | |
| 22 | letters = sorted(string.lower()) |
| 23 | return len(letters) == len(set(letters)) |
| 24 | |
| 25 | |
| 26 | if __name__ == "__main__": |