Add u4/word_count.py
This commit is contained in:
parent
ae3d68d172
commit
ac9290f67a
9
u4/word_count.py
Normal file
9
u4/word_count.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from collections import Counter
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def count_words(sentence):
|
||||||
|
pattern = r"[a-zA-ZáčďéíĺľňóôŕšťúýžÁČĎÉÍĹĽŇÓÔŔŠŤÚÝŽ0-9]+(?:'[a-zA-ZáčďéíĺľňóôŕšťúýžÁČĎÉÍĹĽŇÓÔŔŠŤÚÝŽ0-9]+)?"
|
||||||
|
clean_sentence = sentence.lower()
|
||||||
|
found_words = re.findall(pattern, clean_sentence)
|
||||||
|
return dict(Counter(found_words))
|
||||||
Loading…
Reference in New Issue
Block a user