Parameterized Functions without Classes

Christopher T King squirrel at WPI.EDU
Sat Jun 26 15:02:39 EDT 2004


On Fri, 25 Jun 2004, Peter Otten wrote:

> Christopher T King wrote:
>
> > def partial(func,*args,**kw):
> >     return lambda *a,**k: func(*(args+a),**dict(kw.items()+k.items()))
> 
> In what way is that different from using an ordinary function? 
> def partial(func, *args, **kw):
>     def call(*a, **k): 
>         return func(*(args+a), **dict(kw.items()+k.items()))    
>     return call

It's not, other than that mine is shorter and less readable :P

My point of demonstrating the use of partial() though (this is in response
to Christian also) is that along with 2.4 functions such as itemgetter()  
and attrgetter() and list/generator comprehensions, it will help remove
the need for nearly all uses of lambda functions or their equivalent 
nested functions.




More information about the Python-list mailing list