Skip to content

fix: space count in strings/word_occurrence.py #1896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion strings/word_occurrence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Created by sarathkaul on 17/11/19
# Modified by Arkadip Bhattacharya(@darkmatter18) on 20/04/2020
from collections import defaultdict


Expand All @@ -10,10 +11,12 @@ 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
for word in sentence.split(" "):
for word in sentence.split():
occurrence[word] += 1
return occurrence

Expand Down