bad recursion, still works

iu2 israelu at elbit.co.il
Wed Jul 16 03:47:35 EDT 2008


On Jul 16, 2:21 am, Michael Torrie <torr... at gmail.com> wrote:
> iu2 wrote:
> > I still don't understand: In each recursive call to flatten, acc
> > should be bound to a new [], shouldn't it? Why does the binding happen
> > only on the first call to flatten?
>
> Nope.  In each new call it's (re)bound to the same original list, which
> you've added to as your function continues--it's mutable.  Default
> variables that are bound to mutable objects are one of the big caveats
> that is mentioned in the FAQ.

Thanks guys, it's clear now



More information about the Python-list mailing list