From 54ad7dcdbc38bdf971aebc7ba499187f9f620582 Mon Sep 17 00:00:00 2001 From: shirmn <“shirmn@gmail.com”> Date: Wed, 27 Nov 2019 11:25:19 +0200 Subject: [PATCH 1/2] home work --- Challenge.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Challenge.py diff --git a/Challenge.py b/Challenge.py new file mode 100644 index 0000000..185a845 --- /dev/null +++ b/Challenge.py @@ -0,0 +1,12 @@ +from collections import Counter + +f = open("text.txt", "r") +if f.mode == 'r': + contents = f.read().split() + print(contents) + +word_count = Counter(contents) +print(word_count.most_common(1)) + + + From a71b578cf4aa073879687b7ec01ed13fa9386314 Mon Sep 17 00:00:00 2001 From: shirmn <“shirmn@gmail.com”> Date: Thu, 28 Nov 2019 11:35:47 +0200 Subject: [PATCH 2/2] edit file --- Challenge.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Challenge.py b/Challenge.py index 185a845..63941cf 100644 --- a/Challenge.py +++ b/Challenge.py @@ -1,12 +1,21 @@ -from collections import Counter f = open("text.txt", "r") if f.mode == 'r': contents = f.read().split() print(contents) -word_count = Counter(contents) -print(word_count.most_common(1)) +countDict={} +for word in contents: + if word in countDict: + countDict[word]=countDict[word]+1 + else: + countDict[word] =1 +max= max(countDict, key=countDict.get) +print("The word " +max + " is the most recurring word in that file") + + + +f.close() \ No newline at end of file