def HammingDistance(string_1, string_2):
    assert len(string_1) == len(string_2)
return sum(c1 != c2 for c1, c2 in zip(string_1, string_2))

def MotifCount(string1, substring, d):
    for i in range(len(string1) - len(substring) + 1):
        if HammingDistance(string1[i:i + len(substring)], substring) <= d:
            print(i)
MotifCount(
    'CGCCCGAATCCAGAACGCATTCCCATATTTCGGGACCACTGGCCTCCACGGTACGGACGTCAATCAAAT',
    'ATTCTGGA', 3)
How to optimize a python script which runs for 4**k times?