Skip to content

Commit 4c06bd4

Browse files
committed
improve
1 parent 9760475 commit 4c06bd4

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

genetic_algorithm/basic_string.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def mutate(child: str, genes: list[str]) -> str:
5454
"""
5555
child_list = list(child)
5656
if random.uniform(0, 1) < MUTATION_PROBABILITY:
57-
random.randint(0, len(child)-1) = random.choice(genes)
57+
random_index = random.randint(0, len(child)-1)
58+
child_list[random_index] = random.choice(genes)
59+
5860
return "".join(child_list)
5961

6062

0 commit comments

Comments
 (0)