def process_lines(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as infile:
lines = infile.readlines()
changes = []
for i in range(0, len(lines), 2):
first_set = set(lines[i].strip().split())
second_list = lines[i+1].strip().split()
unique_words = [word for word in second_list if word not in first_set]
changes.extend(unique_words)
with open(output_file, 'w', encoding='utf-8') as outfile:
outfile.write(" ".join(changes) + '\n')
process_lines('darkness.txt', 'changes.txt')
В файле darkness.txt записаны пары строк. Из каждой пары выберите слова, которые есть во второй строке, но нет в первой. Запишите их в исходном порядке в файл changes.txt. Слова в строках разделены пробелами.
В задаче ничего не вводится и не выводится, все действия производятся с указанными файлами.
Once, when he was a child, the electricity went out
Once upon a time he went a fairy road
and his mother found and lit the last candle
Mother went out and found the last apple
This short hour, while the candle was burning
was an hour of wonderful discoveries
Once upon time fairy road
Mother went out apple
an hour of wonderful discoveries
Mother and son sat together
together with any friend and son
strangely transformed sincerely wishing
the strangely aliens wishing your world
that the electricity would not turn on
the hedgehog would turn back
for as long as possible
for a long time
with any friend
the aliens your world
hedgehog back
a time