-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get Most Frequent Word.py
45 lines (31 loc) · 1.06 KB
/
Get Most Frequent Word.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def get_most_frequent_word(lines):
# Complete this function.
#print(lines)
#print(type(lines))
punc = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
combine_lines = ' '.join(lines)
combine_lines = combine_lines.lower()
#print(combine_lines)
split_words = combine_lines.split()
#print(split_words)
for i in range (0, len(split_words)):
for char in split_words[i]:
if char in punc:
split_words[i]=split_words[i].replace(char,"")
#print(split_words)
count_dict = dict.fromkeys(split_words,0)
#print(count_dict)
for words in split_words:
count_dict[words] = split_words.count(words)
#print(count_dict)
max_count = max(count_dict.values())
most_count=[]
for key, value in count_dict.items():
if value == max_count:
most_count.append(key)
#print(', '.join(most_count))
return ', '.join(most_count)
lines = ["The quick brown fox jumps over the lazy dog.",
"The quick brown fox is quick.",
"Lazy dogs are not quick."]
get_most_frequent_word(lines)