1

I'm trying to try out the DEAP package for python and since I'm not too good in python yet I'm taking baby steps. I'm following along with the overview page and I think I've found an error.

On this site http://deap.readthedocs.org/en/1.0.x/overview.html#algorithms

It seems that this line is in error:

for child1, child2 in zip(offspring[::2], offspring[1::2]):

The variable offspring is a map object so I get an object is not subscriptable error. Is the error mine or is this bad code?

Dean MacGregor
  • 11,847
  • 9
  • 34
  • 72
  • I guess that example is for Python 2.x, where `map` returns a list; this is [no longer the case in 3.x](https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists). If you're using 3.x, try `offspring = list(map(toolbox.clone, offspring))` or `offspring = [toolbox.clone(item) for item in offspring]`. – jonrsharpe Jun 19 '15 at 16:10
  • To be clear: this is neither an error of yours nor bad code, just an issue of incompatible versions. – jonrsharpe Jun 19 '15 at 16:18

0 Answers0