Обновить u4/word_count.py
This commit is contained in:
parent
c2bab639f4
commit
dab28d5075
@ -1,13 +1,16 @@
|
||||
import string
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def count_words(sentence):
|
||||
counts = {}
|
||||
text = sentence.lower()
|
||||
|
||||
for mark in string.punctuation.replace("'", ""):
|
||||
text = text.replace(mark, " ")
|
||||
words = []
|
||||
|
||||
for word in text.split():
|
||||
word = word.strip("'")
|
||||
if word:
|
||||
words.append(word)
|
||||
counts[word] = counts.get(word, 0) + 1
|
||||
|
||||
return dict(Counter(words))
|
||||
return counts
|
||||
Loading…
Reference in New Issue
Block a user