Статья Автор: Гайфутдинов Роберт Данилович

Задача 4

f = open('Z2.txt', 'r', encoding='utf-8')
t = f.readlines()
f.close()
n, k, l = map(int, t[0].split())
txt = ' '.join(t[1:])
words = []
i = 0
L = len(txt)
while i < L:
  if txt[i].isalpha():
    j = i
    while j < L and txt[j].isalpha():
      j += 1
    words.append(txt[i:j].lower())
    i = j
  else:
    i += 1
d = {}
for w in words:
  d[w] = d.get(w, 0) + 1
fd = {}
for w, c in d.items():
  if n <= c <= k and len(w) >= l:
    fd.setdefault(c, []).append(w)
for c in sorted(fd.keys(), reverse=True):
  for w in sorted(fd[c], reverse=True):
    print(w, c)
Загрузка...
Чтобы оставить комментарий, необходимо авторизоваться
💬
Пока нет комментариев. Будьте первым!
Печать