From cd60369b65f7e9df6eb4d39d6530bf0b0791fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D1=81=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=9E=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=82=D1=8F=D0=BD=D0=B0=D1=8F?= Date: Thu, 7 Mar 2024 15:38:18 +0300 Subject: [PATCH] add new part of task --- .../stepik_tasks/percentage_of_letters.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/practica/stepik/stepik_tasks/percentage_of_letters.py b/practica/stepik/stepik_tasks/percentage_of_letters.py index af7c201..ab28e1e 100644 --- a/practica/stepik/stepik_tasks/percentage_of_letters.py +++ b/practica/stepik/stepik_tasks/percentage_of_letters.py @@ -52,4 +52,28 @@ with open ('text.txt', 'r') as text: o = '' t+=b with open ('test.txt', 'w') as text: - text.write(t) \ No newline at end of file + text.write(t) + +# подсчет одинаковых слов и вывод самого большого кол-ва раз +list = {} +ind = 0 +len = 0 +full_list = [] +num = 0 +with open ('text.txt', 'r') as text: + lines = [line.split() for line in text] + for parts in lines: + full_list += parts + for words in full_list: + len +=1 + if ind != (len+1): + if words in full_list: + n = full_list.count(words) + list[words] = (n) + ind+=1 + it = 0 + for key, items in list.items(): + if items > it: + it = items + it_key = key +print (it_key, it)