Algorithms 4th implement with python