u4
This commit is contained in:
parent
cb6a109502
commit
07e462be19
20
u4/word_count.py
Normal file
20
u4/word_count.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
def count_word(sentence):
|
||||||
|
words = []
|
||||||
|
word = ""
|
||||||
|
|
||||||
|
for character in sentence:
|
||||||
|
if character.isalnum() or character == " ":
|
||||||
|
word += character.lower()
|
||||||
|
else:
|
||||||
|
if word.strip("'"):
|
||||||
|
words.append(words.strip("'"))
|
||||||
|
word = ""
|
||||||
|
if word.strip("'"):
|
||||||
|
words.append(word.strip("'"))
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for word in words:
|
||||||
|
result[word] = result.get(word, 0) + 1
|
||||||
|
|
||||||
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user