File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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" ))
You can’t perform that action at this time.
0 commit comments