15 lines
385 B
Python
15 lines
385 B
Python
def count_words(sentence):
|
|
sentence = sentence.lower()
|
|
cleaned = ""
|
|
for symbol in sentence:
|
|
if symbol.isalnum() or symbol == "'":
|
|
cleaned += symbol
|
|
else:
|
|
cleaned += " "
|
|
|
|
counts = {}
|
|
for word in cleaned.split():
|
|
word = word.strip("'")
|
|
if word:
|
|
counts[word] = counts.get(word, 0) + 1
|
|
return counts |