From 602f94bf7f78bf12c8b62fafe380a8c4e8cff72b Mon Sep 17 00:00:00 2001 From: Arkadip Bhattacharya Date: Mon, 20 Apr 2020 20:37:20 +0530 Subject: [PATCH 1/5] fix: space count in strings/word_occurrence.py --- strings/word_occurrence.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/word_occurrence.py b/strings/word_occurrence.py index 7b8f9bee8146..6fd34b63c6cf 100644 --- a/strings/word_occurrence.py +++ b/strings/word_occurrence.py @@ -1,4 +1,5 @@ # Created by sarathkaul on 17/11/19 +# Modified by Arkadip Bhattacharya(@darkmatter18) on 20/04/2020 from collections import defaultdict @@ -15,6 +16,7 @@ def word_occurence(sentence: str) -> dict: # Creating a dictionary containing count of each word for word in sentence.split(" "): occurrence[word] += 1 + if '' in occurrence.keys(): occurrence.pop('') return occurrence From 891290e9fdb393069e9aab791760a59c8ccf1c4e Mon Sep 17 00:00:00 2001 From: Arkadip Bhattacharya Date: Tue, 21 Apr 2020 08:15:32 +0530 Subject: [PATCH 2/5] Update strings/word_occurrence.py Co-Authored-By: Christian Clauss --- strings/word_occurrence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/word_occurrence.py b/strings/word_occurrence.py index 6fd34b63c6cf..caf4b8a6a86c 100644 --- a/strings/word_occurrence.py +++ b/strings/word_occurrence.py @@ -16,7 +16,7 @@ def word_occurence(sentence: str) -> dict: # Creating a dictionary containing count of each word for word in sentence.split(" "): occurrence[word] += 1 - if '' in occurrence.keys(): occurrence.pop('') + occurrence.pop('', None) return occurrence From 2cf062e32ef796059ffe1827bdf92be462d68b2b Mon Sep 17 00:00:00 2001 From: Arkadip Bhattacharya Date: Tue, 21 Apr 2020 16:15:58 +0530 Subject: [PATCH 3/5] Update strings/word_occurrence.py Co-Authored-By: Christian Clauss --- strings/word_occurrence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/word_occurrence.py b/strings/word_occurrence.py index caf4b8a6a86c..529e0230e9c8 100644 --- a/strings/word_occurrence.py +++ b/strings/word_occurrence.py @@ -14,7 +14,7 @@ def word_occurence(sentence: str) -> dict: """ occurrence = defaultdict(int) # Creating a dictionary containing count of each word - for word in sentence.split(" "): + for word in sentence.split(): occurrence[word] += 1 occurrence.pop('', None) return occurrence From 7ceac2e0e82c0601a678c12a35489fc7707f125c Mon Sep 17 00:00:00 2001 From: Arkadip Bhattacharya Date: Tue, 21 Apr 2020 20:44:27 +0530 Subject: [PATCH 4/5] Update strings/word_occurrence.py Co-Authored-By: Christian Clauss --- strings/word_occurrence.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/word_occurrence.py b/strings/word_occurrence.py index 529e0230e9c8..029d42bedfaf 100644 --- a/strings/word_occurrence.py +++ b/strings/word_occurrence.py @@ -11,6 +11,8 @@ def word_occurence(sentence: str) -> dict: >>> all(occurence_dict[word] == count for word, count ... in Counter(SENTENCE.split()).items()) True + >>> dict(word_occurence("Two spaces")) + {'Two': 1, 'spaces': 1} """ occurrence = defaultdict(int) # Creating a dictionary containing count of each word From 39fe3b97e224b61330f163dd08ac7b4786d415d9 Mon Sep 17 00:00:00 2001 From: Arkadip Bhattacharya Date: Tue, 21 Apr 2020 20:47:59 +0530 Subject: [PATCH 5/5] Update word_occurrence.py Seems like, there is no need o `occurrence.pop('', None)` --- strings/word_occurrence.py | 1 - 1 file changed, 1 deletion(-) diff --git a/strings/word_occurrence.py b/strings/word_occurrence.py index 029d42bedfaf..ef612e12dfa4 100644 --- a/strings/word_occurrence.py +++ b/strings/word_occurrence.py @@ -18,7 +18,6 @@ def word_occurence(sentence: str) -> dict: # Creating a dictionary containing count of each word for word in sentence.split(): occurrence[word] += 1 - occurrence.pop('', None) return occurrence