This commit is contained in:
Marege 2026-10-06 14:38:10 +02:00
parent 3fa4554d07
commit 27e56c0e79

18
u4/word_count.py Normal file
View File

@ -0,0 +1,18 @@
def count_words(sentence):
cleand = ""
for i in sentence: #чистим від значків
if i.isalnum():
cleand += i
else:
cleand += " "
cleaned = cleand.split() # пакуєм в ліст
result = {}
for word in cleaned:
if word in result: # дивимся чи є якщо є то пропускаєм
continue
count = 0
for currentword in cleaned:#дивимся чи є в інших таке якщо є то +
if currentword == word:
count += 1
result[word] = count
return result