sturlamolden <[EMAIL PROTECTED]> wrote: > On 18 Mar, 00:58, Jeff Schwab <[EMAIL PROTECTED]> wrote: > >> def make_slope(distance, parts): >> if parts == 0: >> return [] >> >> q, r = divmod(distance, parts) >> >> if r and parts % r: >> q += 1 >> >> return [q] + make_slope(distance - q, parts - 1) > > Beautiful. If Python could optimize tail recursion, it would even run > fast.
This was my first thought, too. But tailcall optimisation wouldn't help here. `make_slope` is not tail recursive, the `+` (aka list.extend) gets executed after the recursion. Marc -- http://mail.python.org/mailman/listinfo/python-list