Suppose I am having two text files 1.txt and 2.txt
The content of 1.txt
as:
['Hi', 'I', 'am']
and
The content of 2.txt
as:
['a', 'boy']
How to join the same and write the same into a new file in time efficient manner, say 3.txt
, which should look like this:
['Hi', 'I', 'am', 'a', 'boy']
I have tried:
import os
file_list = os.listdir("path")
with open('out.txt', 'a+') as outfile:
for fname in file_list:
with open(fname) as infile:
outfile.write(infile.read())