DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.88k stars 1.13k forks source link

DEAP documentation need minor update for python3 #630

Open Tazhio opened 2 years ago

Tazhio commented 2 years ago

This is just a minor issue. On the official documentation https://deap.readthedocs.io/en/master/overview.html, there is a starting tutorial.

Now most people are using python3, and in python 3 the map() function only returns an iterator.

Codes like this will return: TypeError: 'map' object is not subscriptable

fitnesses = map(toolbox.evaluate, pop)
    for ind, fit in zip(pop, fitnesses):
        ind.fitness.values = fit

To solve this, just wrap the map() functions with list.

fitnesses = list(map(toolbox.evaluate, pop))
MatteoCass commented 11 months ago

Thanks a lot @Tazhio! Interestingly, I am running python 3.11 and those lines of code do not throw an error here. But a few lines after, the map function is used to generate the offspring object, which is subsetted in a for loop. Here I do get the TypeError: 'map' object is not subscriptable