Загружаю решение задачи с функцией word_count

This commit is contained in:
eduard ermakov 2023-07-24 23:31:00 +03:00
parent e4c2142663
commit 16995087ba
2 changed files with 25 additions and 6 deletions

View File

@ -1,7 +1,9 @@
def word_count(text):
c = []
import re import re
import numpy as np import numpy as np
def word_count(text):
c = []
final = {} final = {}
a = re.sub("[^А-Яа-я-A-Z-a-z ]", "", text).lower() a = re.sub("[^А-Яа-я-A-Z-a-z ]", "", text).lower()
b = str(a).split() b = str(a).split()

View File

@ -1,3 +1,6 @@
import re
import numpy as np
def verify(message, expected, actual): def verify(message, expected, actual):
a = "=========================" a = "========================="
print(a) print(a)
@ -13,8 +16,6 @@ def verify(message, expected, actual):
def verify_all(dataset): def verify_all(dataset):
summa_success = int() summa_success = int()
summa_failed = int() summa_failed = int()
@ -46,10 +47,26 @@ def max_array(array):
def word_count(text):
c = []
final = {}
a = re.sub("[^А-Яа-я-A-Z-a-z ]", "", text).lower()
b = str(a).split()
c = list(b)
unique_array, count_array = np.unique(c, return_counts=True)
final = zip(unique_array, count_array)
final2 = list(final)
return final2
f = 'Я пришел, я ушел, я нашел'
array = [2, 3, 5, 8, 89, 65, 75, 7895, 2, 1, 1] array = [2, 3, 5, 8, 89, 65, 75, 7895, 2, 1, 1]
dataset = [("Test1", 3, min_array(array)), ("Test2", 7895, max_array(array))] dataset = [("Test1", 3, min_array(array)), ("Test2", 7895, max_array(array)),
("Test3", [('нашел', 1), ('пришел', 1), ('ушел', 1), ('я', 3)], word_count(f))]
verify_all(dataset) verify_all(dataset)