Recently with help of stackoverflow i came to know how to match text files using python now im facing some small problem with same code…it performs following task
Input to program is two text files
File 1
C1orf159
FAM79A
IGFBP2
RNF25
.
.
.
.
File 2
ACVR2B
CACNA1A
RNF25
IGF2
.
.
.
I wrote one python script to extract common words between these two files as follows
file1=open("f1.txt","r")
file2=open("f2.txt","r")
file3=open("overlap.txt","w")
list1=file1.readlines()
list2=file2.readlines()
for line1 in list1:
for line2 in list2:
if line1.strip() in line2.strip():
print line2
file3.write(line2)
this gives result as follows
RNF25
IGF2
.
.
.
But there is a problem in this output second word IGF2 is not there in file1…script is matching IGFBP2 from file1 with IFG2..meaning it is looking for patterns… I dont want this i want exact matches between two files..
Can anybody help to modify my script to get exact matches between two files…
Thanks
Ni
You want
line1.strip() == line2.strip().inin this case will match substrings. You are after exact matches it sounds like.