Hi, thanks for the article, you introduced nicely the concept :)

Original article can be found here (source): Artificial Intelligence on Medium

Hi, thanks for the article, you introduced nicely the concept 🙂

Just some simple tips however on the the coding part, as you could improve it significantely and easily 🙂

Taking the crossover function as an example:

  1. Never use “boolean == True” (or false…) : it is already a condition !
    (len(one)==len(two)) == True => len(one) == len(two)
  2. Put meaning in your variable : I was not sure of what was the method object before the else part
    ex: def crossover(parentOne, parentTwo, nbPoints)
  3. Manage error as the first part of code (simpler to read, once the error-handling code is readen, we can peacefully go on), i.e prefer this:
    if (len(one) != len(two))
    return print(f“Same lengths required (length 1 was {len(one)}, length 2 was…”)
    #then the “ok” code goes here, no more ‘else’ needed
  4. Separate your error messages:
    if (len(one) != …)
    return print(f”Same leng…)
    if nbPoints > 2
    return print(“A maximum of 2 points is authorized”)
  5. Avoid re-computing complex variables (easier to read, faster to run)
    ex: parentOneLenght = len(one)
    # Then you have many occurences of len(one) that you can replace
Final version