avp26/u4/word_count.py
2026-10-06 14:21:26 +02:00

15 lines
316 B
Python

import string
def word_count(text):
words = []
for word in text.lower().split():
cleaned_word = word.strip(string.punctuation)
if cleaned_word:
words.append(cleaned_word)
result = {}
for word in words:
result[word] = result.get(word,0) +1
return result