Python comparing two files partially -
Python comparing two files partially -
i have 2 input file:
input 1:
okay sentence 2 runway 3 runway right runway 1 pathway
four pathway 0 pathway
input 2 :
okay sentence 2 runway 3 runway right runway 0 pathway
one pathway 4 pathway
i have used next code:
def diff(a, b): y = [] x in a: if x not in b: y.append(x) else: b.remove(x) homecoming y open('output_ref.txt', 'r') file1: open('output_ref1.txt', 'r') file2: same = diff(list(file1), list(file2)) print same print "\n" if '\n' in same: same.remove('\n') open('some_output_file.txt', 'w') fo: line in same: fo.write(line)
and expected output :
one pathway
zero pathway
but output getting empty output this. problem don't know how store content files list partially ,then compare , read there. can help me in regard ??
it seems if want have mutual text lines in both files, sets provide way. this:
content1 = set(open("file1", "r")) content2 = set(open("file2", "r")) diff_items = content1.difference(content2)
update: question difference in same sense diff
utility? i.e. order of import (looks examples).
python
Comments
Post a Comment