exercism/python/word-count/word_count.py

16 lines
455 B
Python

def count_words(input_sentence):
sentence = input_sentence.lower()
# blocked_characters = [',', '.', ';', ':']
# sentence = ''.join(item for item in sentence if item.isalnum())
words = sentence.split()
result = {}
for word in words:
mod_string = ""
for elem in word:
if elem.isalnum() or elem == "'":
mod_string += elem
result[mod_string] = words.count(word)
return result