Skip to content
Open
Changes from 3 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
21 changes: 21 additions & 0 deletions Python-Home-Challenges/Yarin_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

def most_common_word(file_name):
Copy link
Copy Markdown
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

words_dict={}
with open(file_name) as file:
data_set=file.read()
split_it= data_set.split()
for word in split_it:
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])



if __name__== "__main__":
file_name = input("insert file path: ")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it is a bit risky to ask user to enter file name, if your decision is to do so, you man want to use some validation for his input

most_common_word(file_name)


Copy link
Copy Markdown
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