lambda forms within a loop

Scott David Daniels Scott.Daniels at Acm.Org
Sun Oct 25 21:48:17 CET 2009


Michal Ostrowski wrote:
> ...
> [a,b] = MakeLambda<whatever>()
> print a(10)
> print b(10)

Here is yet another way to solve the problem:

     import functools
     def AddPair(x, q):
         return x + q
     a, b = [functools.partial(AddPair, x) for x in [1, 2]]
     print a(10)
     print b(10)

Or even, since these are numbers:
     a, b = [x.__add__ for x in [1, 2]]
     print a(10)
     print b(10)

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list