Apr-05-2022, 11:56 AM
Build a set of strings then read the second file - this will fix the problem that you are facing.
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')Square Brackets is list comprehension and the [3] is string slicing. menator01 said right only.