From 3c37ec52883c84616c38cf443c9ad7a4752931ae Mon Sep 17 00:00:00 2001 From: ronb <“ronb@gmail.com”> Date: Wed, 27 Nov 2019 11:25:52 +0200 Subject: [PATCH 1/2] HW4RonBiton --- HW4RonBitonPF.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 HW4RonBitonPF.py diff --git a/HW4RonBitonPF.py b/HW4RonBitonPF.py new file mode 100644 index 0000000..dd87937 --- /dev/null +++ b/HW4RonBitonPF.py @@ -0,0 +1,9 @@ +from collections import Counter + +func = open("Hallelujah.txt", "r") +if func.mode == 'r': + contents = func.read().split() + print(contents) + +wordsCount = Counter(contents) +print(wordsCount.most_common(1)) \ No newline at end of file From f674932098d0b6cc0d6e511d55e85b2a781b063d Mon Sep 17 00:00:00 2001 From: ronb <“ronb@gmail.com”> Date: Sun, 1 Dec 2019 21:53:40 +0200 Subject: [PATCH 2/2] update the code --- HW4RonBitonPF.py | 9 --------- HW4RonBitonPFNEW.py | 11 +++++++++++ song.txt | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) delete mode 100644 HW4RonBitonPF.py create mode 100644 HW4RonBitonPFNEW.py create mode 100644 song.txt diff --git a/HW4RonBitonPF.py b/HW4RonBitonPF.py deleted file mode 100644 index dd87937..0000000 --- a/HW4RonBitonPF.py +++ /dev/null @@ -1,9 +0,0 @@ -from collections import Counter - -func = open("Hallelujah.txt", "r") -if func.mode == 'r': - contents = func.read().split() - print(contents) - -wordsCount = Counter(contents) -print(wordsCount.most_common(1)) \ No newline at end of file diff --git a/HW4RonBitonPFNEW.py b/HW4RonBitonPFNEW.py new file mode 100644 index 0000000..586f5a2 --- /dev/null +++ b/HW4RonBitonPFNEW.py @@ -0,0 +1,11 @@ + + +file_song =open("song.txt","r") +data=file_song.read().split() +dict = {} +for i in data: + if i in dict: + dict[i] = dict[i] + 1 + else: + dict[i] = 1 +print(f'the word that appears most is: {max(dict, key=dict.get)}, And it appears {dict[max(dict, key=dict.get)]} times') \ No newline at end of file diff --git a/song.txt b/song.txt new file mode 100644 index 0000000..21bb24d --- /dev/null +++ b/song.txt @@ -0,0 +1,16 @@ + +Well I heard there was a secret chord +That David played and it pleased the Lord +But you don't really care for music, do you? +Well it goes like this: +The fourth, the fifth, the minor fall and the major lift +The baffled king composing Hallelujah + +Hallelujah, Hallelujah, Hallelujah, Hallelujah... + +Well your faith was strong but you needed proof +You saw her bathing on the roof +Her beauty and the moonlight overthrew ya +She tied you toher kitchen chair +She broke your throne and she cut your hair +And from your lips she drew the Hallelujah