Skip to content

Commit 82c3786

Browse files
author
root
committed
len() was called iteratively, put it outside loop
1 parent 8d9eeb5 commit 82c3786

File tree

3 files changed

+2
-1
lines changed

3 files changed

+2
-1
lines changed

__pycache__/grid.cpython-34.pyc

1.72 KB
Binary file not shown.

__pycache__/utils.cpython-34.pyc

22.1 KB
Binary file not shown.

search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ def genetic_algorithm(population, fitness_fn, ngen=1000, pmut=0.1):
477477
"[Fig. 4.8]"
478478
for i in range(ngen):
479479
new_population = []
480-
for i in len(population):
480+
len_population = len(population)
481+
for i in len_population:
481482
fitnesses = list(map(fitness_fn, population))
482483
p1, p2 = weighted_sample_with_replacement(population, fitnesses, 2)
483484
child = p1.mate(p2)

0 commit comments

Comments
 (0)