Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Python-Home-Challenges/Yarin_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

def most_common_word(file_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for using functions
but, best practice, is to create few functions, with each one of them doing 1 thing only

split_it = split_text(file_name)
count_words_get_max(split_it)


def split_text(file_name):
with open(file_name) as file:
data_set = file.read()
split_it = data_set.split()
return split_it


def count_words_get_max(split_words):
words_dict = {}
for word in split_words:
if word in words_dict.keys():
words_dict[word] += 1
else:
words_dict.update({word: 1})
maximum = max(words_dict, key=words_dict.get)
print(maximum, words_dict[maximum])


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure you code pass Flask8 lint validation

if __name__ == "__main__":
most_common_word("summary.txt")
Loading