Skip to content

Commit 43777b7

Browse files
gabrielsimasLuís Gabriel Nascimento Simas
andauthored
Release/1.0.0 (#4)
* Make README.md * Feature/challenge solution (#3) * Solution given for challenge * Deleting uneeded code! --------- Co-authored-by: Luís Gabriel Nascimento Simas <luis.gabriel_thera@prestador.globo> --------- Co-authored-by: Luís Gabriel Nascimento Simas <luis.gabriel_thera@prestador.globo>
1 parent 6b53a4c commit 43777b7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from models.frequent_word_finder import FrequentWordFinder
2+
3+
4+
words = ["love", "peace", "joy", "love", "happiness", "love", "joy"]
5+
6+
finder = FrequentWordFinder(words)
7+
8+
finder.find_the_most_frequent_word()
9+
10+
result = f"""
11+
The most frequent word is {finder.most_frequent}
12+
with {finder.word_count[finder.most_frequent]} occurrences."""
13+
14+
print(result)

src/models/frequent_word_finder.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class FrequentWordFinder:
2+
def __init__(self, wordlist):
3+
self._wordlist = wordlist
4+
self._word_count = {}
5+
self._most_frequent = ""
6+
7+
@property
8+
def most_frequent(self):
9+
return self._most_frequent
10+
11+
@property
12+
def word_count(self):
13+
return self._word_count
14+
15+
def _count_ocurrences(self):
16+
for word in self._wordlist:
17+
self._word_count[word] = self._word_count.get(word, 0) + 1
18+
19+
def find_the_most_frequent_word(self):
20+
self._count_ocurrences()
21+
self._most_frequent = max(self._word_count, key=self._word_count.get)

0 commit comments

Comments
 (0)