Re: questions about functions inside a function

2007-07-16 Thread Bruno Desthuilliers
Jeremy Sanders a écrit : > [EMAIL PROTECTED] wrote: > > >>What I want is, the value of i should be bounded to the anonymous >>function. And the output should like this: > > ... > >>How to achieve this? > > > This doesn't answer your question (others have), but another (perhaps > clearer) way

questions about functions inside a function

2007-07-16 Thread [EMAIL PROTECTED]
I want to create a list of function. Here is my code: In [9]: a = [] In [10]: for i in range(4): : b = lambda : i**2 : a.append(b) : : In [11]: for f in a: : f() : : 9 9 9 9 What I want is, the value of i should be bounded to t

Re: questions about functions inside a function

2007-07-16 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote: > What I want is, the value of i should be bounded to the anonymous > function. And the output should like this: ... > How to achieve this? This doesn't answer your question (others have), but another (perhaps clearer) way to do such things is something like class MyFunc

Re: questions about functions inside a function

2007-07-16 Thread [EMAIL PROTECTED]
Duncan Booth wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >> In order to make sure all variables be larger than 0, I tried to created >> constraint function like this: >> >> cons = [] >> for i in range(N): >> c = lambda x: x[i] - 1e-10 >> cons.append(c) >> >> But when functi

Re: questions about functions inside a function

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 16, 4:49 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: (snipped) > > What I want is, the value of i should be bounded to the anonymous function. > And the output should like this: > > for f in a: > print f() > 0 > 1 > 4 > 9 > > How to achieve this? > > Thanks a lot! The functo

Re: questions about functions inside a function

2007-07-16 Thread Duncan Booth
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > In order to make sure all variables be larger than 0, I tried to created > constraint function like this: > > cons = [] > for i in range(N): > c = lambda x: x[i] - 1e-10 > cons.append(c) > > But when functions in cons are evaluated, the

Re: questions about functions inside a function

2007-07-16 Thread [EMAIL PROTECTED]
Hi, Duncan Booth wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >> What I want is, the value of i should be bounded to the anonymous >> function. And the output should like this: >> >> for f in a: >> print f() >> 0 >> 1 >> 4 >> 9 >> >> How to achieve this? > > Use default arguments

Re: questions about functions inside a function

2007-07-16 Thread Wildemar Wildenburger
Wildemar Wildenburger wrote: >> for f in a: >> print f() >> 0 >> 1 >> 4 >> 9 >> >> How to achieve this? >> >> Thanks a lot! >> >> >> > I fail to see the point, sorry. Why would you want that? If you simply > want a list of values you do: > > a = [i**2 for i in range(4)]

Re: questions about functions inside a function

2007-07-16 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I want to create a list of function. > > Here is my code: > In [9]: a = [] > > In [10]: for i in range(4): >: b = lambda : i**2 >: a.append(b) >: >: > > In [11]: for f in a: >: f() >: >: > 9 > 9 > 9

Re: questions about functions inside a function

2007-07-16 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote: > I want to create a list of function. > > Here is my code: > In [9]: a = [] > > In [10]: for i in range(4): > : b = lambda : i**2 > : a.append(b) > : > : > > In [11]: for f in a: > : f() > : > : > 9 > 9 >

Re: questions about functions inside a function

2007-07-16 Thread Duncan Booth
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > What I want is, the value of i should be bounded to the anonymous > function. And the output should like this: > > for f in a: > print f() > 0 > 1 > 4 > 9 > > How to achieve this? Use default arguments when defining your function: default ar