此解决方案一次性读取两个文件,排除空白行,并打印公共行,无论它们在文件中的位置如何:
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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)