문제

I have 2 different text files.

File1.txt contains:

program
RAM
Python
parser

File2.txt contains:

file
1234
program

I want to perform an union of these both files such that i get an output file3.txt which contains:

program
RAM
Python
parser
file
1234

Is it possible to program this in python? I use python 2.7

도움이 되었습니까?

해결책

with open("File1.txt") as fin1: lines = set(fin1.readlines())
with open("File2.txt") as fin2: lines.update(set(fin2.readlines()))
with open("file3.txt", 'w') as fout: fout.write('\n'.join(list(lines)))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top