with open("10-million-combos.txt", encoding="cp850") as infile: for line in infile: counter2 += 1 if re.search('123456$', line): counter += 1