u4
This commit is contained in:
parent
7b4b96d08a
commit
d9fa93a26c
19
u4/word_count.py
Normal file
19
u4/word_count.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
def count_words(sentence):
|
||||||
|
dict = {}
|
||||||
|
separators = [".", ",", ":", "!", "?", "\n", "\t", "'", " "]
|
||||||
|
|
||||||
|
previous_i = 0
|
||||||
|
for i, chr in enumerate(sentence):
|
||||||
|
if chr in separators:
|
||||||
|
word = sentence[previous_i:i]
|
||||||
|
previous_i = i + 1
|
||||||
|
word = word.lower().strip(" ")
|
||||||
|
if word in separators or word == "":
|
||||||
|
continue
|
||||||
|
if word in dict:
|
||||||
|
print(dict)
|
||||||
|
dict[word] = dict[word] + 1
|
||||||
|
print(dict)
|
||||||
|
else:
|
||||||
|
dict.update({word : 1})
|
||||||
|
return dict
|
||||||
Loading…
Reference in New Issue
Block a user