I am trying to join 24 files (i showed example of 3 files below). They all have 2 columns. The first columns is common to all. The files are tab delimited eg
Note: Where files check_file_check_file1212134, check_file_check_file1212135 and check_file_check_file1212136 are files file1, file2 and file3 respectively.
import os
import collections
d=collections.defaultdict(list)
cnt=0
for f in sorted(os.listdir('dir')):
with open('dir/'+f) as file:
for line in file:
t=line.split(" ")
if t[0] not in d and cnt==1:
d[t[0]]=['NA']*cnt
d[t[0]].append(t[1])
cnt+=1
for i in sorted(d):
print(i," ".join(map(lambda x: x.replace("\n",""), d)),end=" ")
if len(d)<cnt:
for i in range(cnt-len(d)):
print('NA',end="")
print("")