diff --git a/u4/word_count.py b/u4/word_count.py index b04f26d..addb945 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,14 +1,10 @@ import re - def count_words(text): - words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE) + words = re.findall(r"\b[\w]+(?:'[\w]+)?\b", text.lower(), re.UNICODE) result = {} for word in words: - if word in result: - result[word] += 1 - else: - result[word] = 1 + result[word] = result.get(word, 0) + 1 return result \ No newline at end of file