/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/python/lab-1126-001/main.py
14 строк
472 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
from collections import Counter def top_words(path: str, n: int = 5) -> list[tuple[str, int]]: counter: Counter[str] = Counter() with open(path, "r", encoding="utf-8") as f: for line in f: for word in line.lowersplit(): word = word.strip(".,!?;:\"'()[]") if word: counter[word] += 1 return counter.most_common(n) for word, freq in top_words("article.txt"): print(f"{word}: {freq}")