Skip to content

Commit 12f6fe9

Browse files
authored
Added file
1 parent 4800513 commit 12f6fe9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

letterCount.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Have the function LetterCountI(str) take the str parameter being passed
3+
and return the first word with the greatest number of repeated letters. For
4+
example: "Today, is the greatest day ever!" should return 'greatest' because
5+
it has 2 e's (and 2 t's) and it comes before 'ever' which also has 2 e's. If
6+
there are no words with repeating letters return -1. Words will be separated
7+
by spaces.
8+
9+
10+
Example:
11+
Input: "Hello apple pie"
12+
Output: Hello
13+
14+
Input: "No words"
15+
Output: -1
16+
'''
17+
18+
def LetterCountI(strParam):
19+
str_arr = strParam.split()
20+
count = 0
21+
greatest_length = '-1'
22+
23+
for i in range(len(str_arr)):
24+
for j in range(len(str_arr[i])):
25+
new_count = 0
26+
for k in range(j+1, len(str_arr[i])):
27+
if str_arr[i][j] == str_arr[i][k]:
28+
new_count+=1
29+
if new_count > count:
30+
count = new_count
31+
greatest_length = str_arr[i]
32+
return greatest_length
33+
34+
print(LetterCountI("Hello apple pie"))

0 commit comments

Comments
 (0)