Skip to content

Commit e95208f

Browse files
Create IsIsogram
1 parent 78f5532 commit e95208f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Codewars/IsIsogram

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# An isogram is a word that has no repeating letters, consecutive or non-consecutive.
2+
# Implement a function that determines whether a string that contains only letters is an isogram.
3+
# Assume the empty string is an isogram. Ignore letter case.
4+
5+
6+
# isIsogram( "Dermatoglyphics" ) == true
7+
# isIsogram( "aba" ) == false
8+
# isIsogram( "moOse" ) == false // -- ignore letter case
9+
10+
11+
# My solution
12+
13+
def is_isogram(string):
14+
if not string:
15+
return True
16+
else:
17+
text = string.lower()
18+
for i in text:
19+
count = text.count(i, 0, len(text)+1)
20+
if count > 1 :
21+
return False
22+
return True
23+
24+
25+
# Best solutions
26+
27+
def is_isogram(string):
28+
return len(string) == len(set(string.lower()))

0 commit comments

Comments
 (0)