Skip to content

Commit 098be35

Browse files
fix: space count in strings/word_occurrence.py (TheAlgorithms#1896)
* fix: space count in strings/word_occurrence.py * Update strings/word_occurrence.py Co-Authored-By: Christian Clauss <[email protected]> * Update strings/word_occurrence.py Co-Authored-By: Christian Clauss <[email protected]> * Update strings/word_occurrence.py Co-Authored-By: Christian Clauss <[email protected]> * Update word_occurrence.py Seems like, there is no need o `occurrence.pop('', None)` Co-authored-by: Christian Clauss <[email protected]>
1 parent 24b2aec commit 098be35

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

strings/word_occurrence.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Created by sarathkaul on 17/11/19
2+
# Modified by Arkadip Bhattacharya(@darkmatter18) on 20/04/2020
23
from collections import defaultdict
34

45

@@ -10,10 +11,12 @@ def word_occurence(sentence: str) -> dict:
1011
>>> all(occurence_dict[word] == count for word, count
1112
... in Counter(SENTENCE.split()).items())
1213
True
14+
>>> dict(word_occurence("Two spaces"))
15+
{'Two': 1, 'spaces': 1}
1316
"""
1417
occurrence = defaultdict(int)
1518
# Creating a dictionary containing count of each word
16-
for word in sentence.split(" "):
19+
for word in sentence.split():
1720
occurrence[word] += 1
1821
return occurrence
1922

0 commit comments

Comments
 (0)