From 1387d6e4e512c584615822be47c23f73f85955b0 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 1 Nov 2021 18:25:37 +0100 Subject: [PATCH] continue WIP --- python/word-count/word_count.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python/word-count/word_count.py b/python/word-count/word_count.py index d0bdbdc..6d198ce 100644 --- a/python/word-count/word_count.py +++ b/python/word-count/word_count.py @@ -1,11 +1,15 @@ def count_words(input_sentence): sentence = input_sentence.lower() - sentence = ' '.join(filter(str.isalnum, sentence)) - # for character in blocked_characters: - # sentence = sentence.replace(character, " ") + # blocked_characters = [',', '.', ';', ':'] + # sentence = ''.join(item for item in sentence if item.isalnum()) + words = sentence.split() result = {} for word in words: - result[word] = words.count(word) + mod_string = "" + for elem in word: + if elem.isalnum() or elem == "'": + mod_string += elem + result[mod_string] = words.count(word) return result