Mar-29-2021, 07:31 PM
Can still use a set. It will be more efficient than comparing strings. First build the set of strings you are looking for, then read in the second file and check against the set.
with open(DIR/'lines_to_look_for.txt', 'r') as file: lines = set([line.strip().split(',')[3] for line in file]) with open(DIR/'check_for_lines.txt', 'r') as file: for line in file: line = line.strip() if line.split(',')[3] in lines: print(f'{line} MATCH') else: print(f'{line} NO MATCH')