I am assuming your file is not super huge, and you ve enough memory:
Here is the file1 :
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
VGF--->V_VM_VF
KGF--->V_VM_VF P_NSF SSF
VGF--->V_VM_VF KLF NFG_JP
Here is the file2 :
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
VGF--->V_VM_VF
VGF--->V_VM_VF
VGF--->V_VM_VF
KGF--->V_VM_VF P_NSF SSF
KGF--->V_VM_VF P_NSF SSF
VGF--->V_VM_VF
VGF--->V_VM_VF
KGF--->V_VM_VF P_NSF SSF
KGF--->V_VM_VF P_NSF SSF
VGF--->V_VM_VF KLF NFG_JP
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
VGF--->V_VM_VF
VGF--->V_VM_VF KLF NFG_JP
VGF--->V_VM_VF KLF NFG_JP
VGF--->V_VM_VF
VGF--->V_VM_VF KLF NFG_JP
VGF--->V_VM_VF KLF NFG_JP
VGF--->V_VM_VF KLF NFG_JP
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
Here is the code:
#!/usr/bin/python
import pprint
lines1 = set()
with open('txt1', 'r') as f1:
lines1 = set([x.strip() for x in f1.readlines()])
line_dict = dict()
with open('txt2', 'r') as f2:
for line in f2.readlines():
line = line.strip()
line_dict.setdefault(line, 0)
line_dict[line] = line_dict.get(line, 0) + 1
for line in lines1:
print '%s : %d' % (line, line_dict.get(line, 0))
Output:
VGF--->V_VM_VF : 7
VGF--->V_VM_VF KLF NFG_JP : 6
KGF--->V_VM_VF P_NSF SSF : 4
NP--->N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU : 8