mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Fix typo in word_occurrence.py (#6154)
word_occurence -> word_occurrence
This commit is contained in:
parent
ec54da34b9
commit
dceb30aad6
|
@ -4,15 +4,15 @@ from collections import defaultdict
|
||||||
from typing import DefaultDict
|
from typing import DefaultDict
|
||||||
|
|
||||||
|
|
||||||
def word_occurence(sentence: str) -> dict:
|
def word_occurrence(sentence: str) -> dict:
|
||||||
"""
|
"""
|
||||||
>>> from collections import Counter
|
>>> from collections import Counter
|
||||||
>>> SENTENCE = "a b A b c b d b d e f e g e h e i e j e 0"
|
>>> SENTENCE = "a b A b c b d b d e f e g e h e i e j e 0"
|
||||||
>>> occurence_dict = word_occurence(SENTENCE)
|
>>> occurence_dict = word_occurrence(SENTENCE)
|
||||||
>>> all(occurence_dict[word] == count for word, count
|
>>> all(occurence_dict[word] == count for word, count
|
||||||
... in Counter(SENTENCE.split()).items())
|
... in Counter(SENTENCE.split()).items())
|
||||||
True
|
True
|
||||||
>>> dict(word_occurence("Two spaces"))
|
>>> dict(word_occurrence("Two spaces"))
|
||||||
{'Two': 1, 'spaces': 1}
|
{'Two': 1, 'spaces': 1}
|
||||||
"""
|
"""
|
||||||
occurrence: DefaultDict[str, int] = defaultdict(int)
|
occurrence: DefaultDict[str, int] = defaultdict(int)
|
||||||
|
@ -23,5 +23,5 @@ def word_occurence(sentence: str) -> dict:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for word, count in word_occurence("INPUT STRING").items():
|
for word, count in word_occurrence("INPUT STRING").items():
|
||||||
print(f"{word}: {count}")
|
print(f"{word}: {count}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user