U4
This commit is contained in:
parent
3fa4554d07
commit
27e56c0e79
18
u4/word_count.py
Normal file
18
u4/word_count.py
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user