def mutations(word, hamming_distance, charset='ATCG'):
    for indices in itertools.combinations(list(range(len(word))), hamming_distance):
        for replacements in itertools.product(charset, repeat=hamming_distance
            ):
            mutation = list(word)
for index, replacement in zip(indices, replacements):
    mutation[index] = replacement
yield ''.join(mutation)
Inverse of Hamming Distance