-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlettercount.py
More file actions
27 lines (24 loc) · 941 Bytes
/
lettercount.py
File metadata and controls
27 lines (24 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Have the function LetterCount(str) take the str parameter being passed
# and return the first word with the greatest number of repeated letters.
# For example: "Today, is the greatest day ever!" should return greatest
# because it has 2 e's (and 2 t's) and it comes before ever which also has 2 e's.
# If there are no words with repeating letters return -1. Words will be separated by spaces.
def LetterCountI(str) :
arr = str.split(" ")
l = len(arr)
count = 0
word = "-1"
for i in range( l):
for a in range(len(arr[i])):
countNew = 0
b = a + 1
for b in range (len(arr[i])):
if arr[i][a] == arr[i][b]:
countNew += 1
if (countNew > count):
count = countNew
word = arr[i]
return word
if __name__ == "__main__":
str = input("Enter ur value")
print(LetterCountI(str))