On Sun, Sep 14, 2008 at 10:01 AM, cnb <[EMAIL PROTECTED]> wrote: > this recursive definition of sum thrumped me, is this some sort of > gotcha or am I just braindead today? > and yes i know this is easy a a for x in xs acc += x or just using the > builtin. > > def suma(xs, acc=0): > if len(xs) == 0: > acc > else: > suma(xs[1:], acc+xs[0])
You're just missing the "return" statements? def suma(xs, acc=0): if len(xs) == 0: return acc else: return suma(xs[1:], acc+xs[0]) Regards Marco -- Marco Bizzarri http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list