from itertools import islice
for i in range(0, len(nodes)):
    fragment = nodes[i]
for l in range(0, length1):
    count = sum(f != f1 for f, f1 in zip(fragement, islice(Text, 1, l + k)))
if count <= Num_mismatches:
    count2[i] += 1
result2[i] = fragment
result.append(fragment)
if count2[i] > maxval:
    maxval = count2[i]
Improve speed of nested loop