Assuming you can read the data from file and hold it into two string say input1 and input2 below code should do what you are looking for
word_list_1 = input1.split(" ")
for str in input2.split("\n"):
word_list_2 = str.split(" ")
for word in word_list_1:
if word in word_list_2:
sys.stdout.write("1")
else:
sys.stdout.write("0")
sys.stdout.write("")
sys.stdout.write("\n")
solved python code to create a merged file