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
[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
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
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
"[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
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
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)]
[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
[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
>
"[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
10 matches
Mail list logo