Re: recursion gotcha?

2008-09-14 Thread Boris Borcic
cnb 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(

Re: recursion gotcha?

2008-09-14 Thread Arnaud Delobelle
On Sep 14, 9:44 am, "Marco Bizzarri" <[EMAIL PROTECTED]> wrote: > On Sun, Sep 14, 2008 at 10:08 AM, Marco Bizzarri > > > > <[EMAIL PROTECTED]> wrote: > > 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 > >> got

Re: recursion gotcha?

2008-09-14 Thread Marco Bizzarri
On Sun, Sep 14, 2008 at 10:08 AM, Marco Bizzarri <[EMAIL PROTECTED]> wrote: > 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

Re: recursion gotcha?

2008-09-14 Thread rs387
On Sep 14, 9:01 am, cnb <[EMAIL PROTECTED]> wrote: > def suma(xs, acc=0): >         if len(xs) == 0: >                 acc >         else: >                 suma(xs[1:], acc+xs[0]) > > it returns none. Yep, that's because there is no "return" statement anywhere. Python doesn't return expressions "

Re: recursion gotcha?

2008-09-14 Thread Marco Bizzarri
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(x

recursion gotcha?

2008-09-14 Thread cnb
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+x