Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW Python - Saar Cohen #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions Python-Home-Challenges/recurring word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

where_file = input('Enter the file route: ')
with open(where_file,"r") as file:
my_file =file.readlines()
words_in_text = dict()
for line in my_file:
line = line.strip()
words = line.split(" ")
for word in words:
if word in words_in_text:
words_in_text[word] = words_in_text[word] + 1
else:
words_in_text[word] = 1
for key in list(words_in_text.keys()):
print(key, ":", words_in_text[key])
print("---------------")
max1=0
for highest in list(words_in_text.keys()):
if max1 < words_in_text[highest]:
max1 = words_in_text[highest]
key1 = highest
print (("The most recurring word is: {key12} with {max12} times").format(key12=key1,max12=max1))
3 changes: 3 additions & 0 deletions Python-Home-Challenges/saar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
saar saar saar saar saar saar saar saar my bdd dss ass aa oeoeoe qwiwie xcld saar
saar lol sms iphone ani vao
haha jaja saar