Re: Question about lambda and variable bindings

2008-03-02 Thread Duncan Booth
Michael Torrie <[EMAIL PROTECTED]> wrote: > poof65 wrote: >> An idea, i don't know if it will work in your case. >> >> for x in xrange(10): >> funcs.append(lambda p,z=x: testfunc(z+2,p)) > > Good idea. I will try it. I also figured out a way to architecture my > program differently to avoid

Re: Question about lambda and variable bindings

2008-03-01 Thread Terry Reedy
"Michael Torrie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I need to use a lambda expression Lambda expressions are a convenience, not a necessity. When having a problem, it sometimes helps to revert to the unabbreviated def statement. tjr -- http://mail.python.org/mail

Re: Question about lambda and variable bindings

2008-03-01 Thread castironpi
On Mar 1, 8:50 pm, Michael Torrie <[EMAIL PROTECTED]> wrote: > I need to use a lambda expression to bind some extra contextual data > (should be constant after it's computed) to a call to a function.  I had > originally thought I could use something like this demo (but useless) code: > > funcs=[] >

Re: Question about lambda and variable bindings

2008-03-01 Thread Michael Torrie
poof65 wrote: > An idea, i don't know if it will work in your case. > > for x in xrange(10): > funcs.append(lambda p,z=x: testfunc(z+2,p)) Good idea. I will try it. I also figured out a way to architecture my program differently to avoid this problem. But this idiom might be handy in certain

Re: Question about lambda and variable bindings

2008-03-01 Thread poof65
An idea, i don't know if it will work in your case. for x in xrange(10): funcs.append(lambda p,z=x: testfunc(z+2,p)) On Sun, Mar 2, 2008 at 3:50 AM, Michael Torrie <[EMAIL PROTECTED]> wrote: > I need to use a lambda expression to bind some extra contextual data > (should be constant after it's

Question about lambda and variable bindings

2008-03-01 Thread Michael Torrie
I need to use a lambda expression to bind some extra contextual data (should be constant after it's computed) to a call to a function. I had originally thought I could use something like this demo (but useless) code: funcs=[] def testfunc(a,b): print "%d, %d" % (a,b) for x in xrange(10):

Re: about lambda

2005-11-20 Thread Rick Wotnaz
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > > Shi Mu wrote: >> what does the following code mean? It is said to be used in the >> calculation of the overlaid area size between two polygons. >> map(lambda x:b.setdefault(x,[]),a) > > The equivalent of : > > def oh_

Re: about lambda

2005-11-20 Thread Duncan Booth
Shi Mu wrote: > what does the following code mean? It is said to be used in the > calculation of the overlaid area size between two polygons. > map(lambda x:b.setdefault(x,[]),a) > > Thanks! Assuming b is a dict, it is roughly equivalent to the following (except that the variables beginning wit

Re: about lambda

2005-11-20 Thread [EMAIL PROTECTED]
Shi Mu wrote: > what does the following code mean? It is said to be used in the > calculation of the overlaid area size between two polygons. > map(lambda x:b.setdefault(x,[]),a) The equivalent of : def oh_my_yet_another_function_name_why_not_use_lambda(x): b.setdefault(x,[]) map(oh_my_yet_an

about lambda

2005-11-20 Thread Shi Mu
what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) Thanks! -- http://mail.python.org/mailman/listinfo/python-list