A simple and flexible GA loop in Python

Yes, yes, I know, Python. I just have been playing around to see how much you can squeeze out of it and I am very surprise of how elegant it can be. Just and example. I am pretty sure you have written way to many customize GA loops that you need to tweak every now and then, if so take a look at the Python version below.

def evolve(self):
    """Implements a simple evolution loop"""
    func\_calls = \[\]
    func\_calls.append(self.evaluate)
    if ( self.env.selection!=None ) : func\_calls.append(self.selection)
    if ( self.env.crossover!=None ) : func\_calls.append(self.crossover)
    if ( self.env.mutation!=None ) : func\_calls.append(self.mutate)
    if ( self.env.replacement!=None ) : func\_calls.append(self.replace)
    \[f() for f in func\_calls for i in range(self.env.length/5)\]
    self.evaluate()
    return (self.best\_fitness,self.best\_individual)

Where the self.env object just contains references to the methods implementing each of the functionalities generically implemented in self.evaluate, etc. Pretty sleek.