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