first
This commit is contained in:
19
count.py
Normal file
19
count.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
from string import ascii_lowercase
|
||||||
|
|
||||||
|
|
||||||
|
def count_words(string):
|
||||||
|
|
||||||
|
word_dict = defaultdict(int)
|
||||||
|
|
||||||
|
words = string.split(' ')
|
||||||
|
|
||||||
|
for word in words:
|
||||||
|
|
||||||
|
word = ''.join(char
|
||||||
|
for char in word.lower()
|
||||||
|
if char in ascii_lowercase + "'")
|
||||||
|
|
||||||
|
word_dict[word] += 1
|
||||||
|
|
||||||
|
return word_dict
|
||||||
Reference in New Issue
Block a user