📜  如何在python代码示例中比较两个文本文件

📅  最后修改于: 2022-03-11 14:45:48.787000             🧑  作者: Mango

代码示例1
with open('some_file_1.txt', 'r') as file1:
    with open('some_file_2.txt', 'r') as file2:
        same = set(file1).intersection(file2)

same.discard('\n')

with open('some_output_file.txt', 'w') as file_out:
    for line in same:
        file_out.write(line)