我会尝试给出一个整体的想法。这没有经过测试,只是描述想法,而不是解决方案!
# open files...
csv_a = f1.readlines()
box_a = [x.split(',') for x in csv_a]
#similar to load list of lists for box_b
box_in_a_not_b = []
box_in_b_not_a = []
box_match_not_perfect = []
while box_a:
line = box_a.pop()
flag=0
while box_b:
bline = box_b.pop()
if line[0]=bline[0] and line[6]=bline[6] and line[7]=bline[7] # 6 & 7 being PREFIX and PHONE_NUMBER indexes
if not all([line[z]==bline[z] for z in range(len(line))]):
box_match_not_perfect.append(line)
box_match_not_perfect.append(bline) # keeps both instances in the 3d file
else:
box_in_b_not_a.append(bline)
flag =1 # match not found, so add line from A to the file with unique
#end of while box_b
if flag==1:
box_in_a_not_b.append(line)
#end of while box_a
in_a_not_b = [','.join(z) for z in box_in_a_not_b] # to get list of csv lines
# use another '\n'.join() to get one big multiline string, or write line by lie to the file
# to save box_in_a_not_b, box_in_b_not_a and box_in_match_not_perfect in corresponding files
#...