Skip to content

Commit b1112e6

Browse files
[Sync Iteration] python/isogram/3
1 parent fd77905 commit b1112e6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Isogram.
3+
4+
Determine if a word or phrase is an isogram.
5+
6+
An isogram (also known as a "non-pattern word") is a word or phrase
7+
without a repeating letter, however spaces and hyphens are allowed
8+
to appear multiple times.
9+
10+
Examples of isograms:
11+
12+
lumberjacks
13+
background
14+
downstream
15+
six-year-old
16+
17+
The word isograms, however, is not an isogram, because the s repeats.
18+
"""
19+
20+
21+
def is_isogram(string: str) -> bool:
22+
"""
23+
Determine if a word or phrase is an isogram.
24+
25+
An isogram is a word or phrase without repeating letters. Spaces and hyphens
26+
are allowed to appear multiple times, but alphabetic characters must be unique
27+
(case-insensitive).
28+
29+
:param string: The word or phrase to check
30+
:type string: str
31+
:returns: True if the string is an isogram, False otherwise
32+
:rtype: bool
33+
"""
34+
# empty string
35+
if not string:
36+
return True
37+
38+
letters: list[str] = [char for char in string.lower() if char.isalpha()]
39+
return len(letters) == len(set(letters))

0 commit comments

Comments
 (0)