Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def filter_text_file(input_file_path, bad_words_file_path, output_file_path):
- with open(input_file_path, 'r') as input_file:
- text = input_file.read()
- with open(bad_words_file_path, 'r') as bad_words_file:
- bad_words = bad_words_file.read().splitlines()
- filtered_text = text
- for bad_word in bad_words:
- filtered_text = filtered_text.replace(bad_word, '')
- with open(output_file_path, 'w') as output_file:
- output_file.write(filtered_text)
- # Пример использования
- input_file_path = 'input.txt' # Путь к исходному файлу
- bad_words_file_path = 'bad_words.txt' # Путь к файлу с неприемлемыми словами
- output_file_path = 'output.txt' # Путь к новому файлу без неприемлемых слов
- filter_text_file(input_file_path, bad_words_file_path, output_file_path)
- print("Новый файл без неприемлемых слов успешно создан.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement