Skip to content

Commit 1183d5e

Browse files
[Sync Iteration] python/isogram/2
1 parent 9f0d17e commit 1183d5e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
letters: list[str] = [char for char in string.lower() if char.isalpha()]
35+
return len(letters) == set(letters)

0 commit comments

Comments
 (0)