Ищем в тексте повторы групп слов
from collections import Counter
def find_repeated_words(text):
sentences = re.split(r'[.!?]', text)
for sentence in sentences:
words = re.findall(r'\b\w{3,}\b', sentence)
word_counts = Counter(words)
repeated_words = [word for word, count in word_counts.items() if count >= 3]
if repeated_words:
print(f"Предложение: '{sentence.strip()}'.")
print(f"Повторяющиеся слова: {', '.join(repeated_words)}\n")
def read_file_and_find_repeated_words(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
text = file.read()
find_repeated_words(text)
# Путь к файлу
file_path = 'фразы.txt'
read_file_and_find_repeated_words(file_path)
Свидетельство о публикации №124062000414