Вы можете попробовать что-то вроде этого:
inputText = []
for file in ['1.txt','2.txt']:
with open(file,'r') as file:
inputText.extend(file.readlines()+['\n'])
with open ('3.txt','w') as output:
for line in inputText:
output.write(line)
или
with open ('3.txt','w') as output:
for file in ['1.txt','2.txt']:
with open(file,'r') as file:
for line in file:
output.write(line)
output.write('\n')
Отредактировано на ваш комментарий:
import re
inputList = []
for file in ['1.txt','2.txt']:
with open(file,'r') as infile:
for line in infile:
inputList.extend(re.sub('[^A-Za-z0-9,]+', '', line).split(","))
print(inputList)
with open('3.txt','w') as outfile:
for line in inputList:
outfile.write(line + '\n')