On Jul 17, 8:27 am, Jeff <[EMAIL PROTECTED]> wrote:
> Thanks, that made things very clear. I like that technique for adding
> memoization via the parameter. That is clever. It would be nice if
> there were a way to have multiple functions close over a shared local
> variable in Python, like let-
Thanks, that made things very clear. I like that technique for adding
memoization via the parameter. That is clever. It would be nice if
there were a way to have multiple functions close over a shared local
variable in Python, like let-binding in lisp.
--
http://mail.python.org/mailman/listinfo/
On Wed, 16 Jul 2008 15:20:23 +0200, Fredrik Lundh wrote:
[snip]
> Hope this helps more than it confuses.
Absolutely. It is wonderfully enlightening. Many thanks.
--
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list
Jeff wrote:
Is this avoidable by using a call to list() in the definition instead?
No. Default values are *always* evaluated when, and only when, the
"def" statement is executed; see:
http://docs.python.org/ref/function.html
Also note that "def" is an executable statement in Python, a
On Jul 16, 1:09 pm, Jeff <[EMAIL PROTECTED]> wrote:
> On Jul 15, 7:21 pm, Michael Torrie <[EMAIL PROTECTED]> 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
On Jul 15, 7:21 pm, Michael Torrie <[EMAIL PROTECTED]> 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)boun
On Jul 16, 2:21 am, Michael Torrie <[EMAIL PROTECTED]> 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)boun
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 conti
On Jul 15, 4:12 pm, iu2 <[EMAIL PROTECTED]> wrote:
> On Jul 15, 9:30 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > On Jul 15, 2:59 pm, iu2 <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I wrote this wrong recursive function that flattens a list:
>
> > > def flatten(lst, acc=[]):
> > > #print 'acc =',
On Jul 15, 9:30 pm, [EMAIL PROTECTED] wrote:
> On Jul 15, 2:59 pm, iu2 <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I wrote this wrong recursive function that flattens a list:
>
> > def flatten(lst, acc=[]):
> > #print 'acc =', acc, 'lst =', lst
> > if type(lst) != list:
> > acc.a
On Jul 15, 2:59 pm, iu2 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I wrote this wrong recursive function that flattens a list:
>
> def flatten(lst, acc=[]):
> #print 'acc =', acc, 'lst =', lst
> if type(lst) != list:
> acc.append(lst)
> else:
> for item in lst:
> f
Hi,
I wrote this wrong recursive function that flattens a list:
def flatten(lst, acc=[]):
#print 'acc =', acc, 'lst =', lst
if type(lst) != list:
acc.append(lst)
else:
for item in lst:
flatten(item)
return acc
a = [1, 2, [3, 4, 5], [6, [7, 8, [9, 10],
12 matches
Mail list logo