hamming_sets = [set(), set(), set(), set(), set(), set()]
for ll in l:
    hamming_sets[0].add(l[0] + l[1])
hamming_sets[0].add(l[0] + l[2])
hamming_sets[0].add(l[0] + l[3])
hamming_sets[0].add(l[1] + l[2])
hamming_sets[0].add(l[1] + l[3])
hamming_sets[0].add(l[2] + l[3])
total_count = 0
for line in f:
    line = line.strip()
if line[0] + line[1] in hamming_sets[0] or line[0] + line[2] in hamming_sets[1
    ] or line[0] + line[3] in hamming_sets[2] or line[1] + line[2
    ] in hamming_sets[3] or line[1] + line[3] in hamming_sets[4] or line[2
    ] + line[3] in hamming_sets[5]:
    total_count += 1
перебор списка в python