hnc-vitalii/HNS/Excercises/27,06,2023/количество слов.py

31 lines
619 B
Python
Raw Permalink Normal View History

2023-09-26 07:29:48 +02:00
def word_count(text):
result = []
x = ('абвгдеёжзийклмнопрстуфхцчшщъыьэюя ')
y = ''
for j in text.lower():
if j in x:
y += j
a = y
c = list(str(a).split())
array1 = []
array2 = []
for q in c:
if q in array1:
index = array1.index(q)
array2[index] += 1
else:
array1.append(q)
array2.append(1)
for i in range(len(array1)):
result.append((array1[i], array2[i]))
return result
f = 'Я пришел, я ушел, я нашел'
print(word_count(f))