From 24093ddcd14ae086d871af487da322c339074916 Mon Sep 17 00:00:00 2001 From: Saar Cohen Date: Sun, 1 Dec 2019 00:46:50 +0200 Subject: [PATCH 1/3] Homework1 --- Python-Home-Challenges/recurring word.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python-Home-Challenges/recurring word.py diff --git a/Python-Home-Challenges/recurring word.py b/Python-Home-Challenges/recurring word.py new file mode 100644 index 0000000..83fcd02 --- /dev/null +++ b/Python-Home-Challenges/recurring word.py @@ -0,0 +1,22 @@ + +where_file = input('Enter the file route: ') +my_file = open(where_file,"r") +print("Your file text is:") +for x in my_file: + print(x) +print("---------------") +words_in_text = dict() +my_file = open(where_file,"r") +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("---------------") +print (max(words_in_text.values())) + From 823e75b0dc0a749efc2789a2c0506e641bee3458 Mon Sep 17 00:00:00 2001 From: Saar Cohen Date: Sun, 1 Dec 2019 11:31:10 +0200 Subject: [PATCH 2/3] Fixed-HW --- Python-Home-Challenges/recurring word.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Python-Home-Challenges/recurring word.py b/Python-Home-Challenges/recurring word.py index 83fcd02..ebbf881 100644 --- a/Python-Home-Challenges/recurring word.py +++ b/Python-Home-Challenges/recurring word.py @@ -1,10 +1,6 @@ where_file = input('Enter the file route: ') my_file = open(where_file,"r") -print("Your file text is:") -for x in my_file: - print(x) -print("---------------") words_in_text = dict() my_file = open(where_file,"r") for line in my_file: @@ -18,5 +14,10 @@ for key in list(words_in_text.keys()): print(key, ":", words_in_text[key]) print("---------------") -print (max(words_in_text.values())) - +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: ", key1," with ",max1, " times") +my_file.close() \ No newline at end of file From 70b7c4a0fe3290dcb5c83683ccedfb44ca2dba2a Mon Sep 17 00:00:00 2001 From: Saar Cohen Date: Tue, 3 Dec 2019 15:59:06 +0200 Subject: [PATCH 3/3] fixed2 --- Python-Home-Challenges/recurring word.py | 7 +++---- Python-Home-Challenges/saar.txt | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Python-Home-Challenges/saar.txt diff --git a/Python-Home-Challenges/recurring word.py b/Python-Home-Challenges/recurring word.py index ebbf881..789248e 100644 --- a/Python-Home-Challenges/recurring word.py +++ b/Python-Home-Challenges/recurring word.py @@ -1,8 +1,8 @@ where_file = input('Enter the file route: ') -my_file = open(where_file,"r") +with open(where_file,"r") as file: + my_file =file.readlines() words_in_text = dict() -my_file = open(where_file,"r") for line in my_file: line = line.strip() words = line.split(" ") @@ -19,5 +19,4 @@ if max1 < words_in_text[highest]: max1 = words_in_text[highest] key1 = highest -print ("The most recurring word is: ", key1," with ",max1, " times") -my_file.close() \ No newline at end of file +print (("The most recurring word is: {key12} with {max12} times").format(key12=key1,max12=max1)) diff --git a/Python-Home-Challenges/saar.txt b/Python-Home-Challenges/saar.txt new file mode 100644 index 0000000..2f0574b --- /dev/null +++ b/Python-Home-Challenges/saar.txt @@ -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 \ No newline at end of file