for j in range(1, len(points)):
    best_split = None
best_cost = lsqFitCost(points, 0, j)
for i in range(0, j):
    cost = solutions[i]['cost'] + split_cost + lsqFitCost(points, i + 1, j)
if cost < best_cost:
    best_cost = cost
best_split = i
if best_split != None:
    solution[j] = {'cost': best_cost, 'splits': solution[best_split][
        'splits'] + [best_split]}
else:
    pass
Segmented least squares algorithm, don't understand this dynamic programming concept at all