Newbie question...

Fredrik Lundh effbot at telia.com
Thu Sep 28 16:03:38 EDT 2000


Hans:
> >>def adder3(**args):
> >>    return reduce(lambda x, y, a=args: x+y, args.values())
> >>
> >>>>> print adder3(good=1, bad=2, ugly=3)
> >>6
> >>>>> print adder3(good="a", bad="b", ugly="c")
> >>"abc"

Mike: 
> >Why do you add 'a=args' to the lambda parameter list? args is in local 
> >namespace and is not a parameter of lambda but a parameter of reduce.

Quinn:
> Try taking it out, and see what happens :)

yeah, let's see what happens:

>>> def adder3(**args):
>>>    return reduce(lambda x, y: x+y, args.values())
>>> adder3(good=1, bad=2, ugly=3)
6

looks okay to me...

> 'args' is *not* in the local namespace of the lambda.

doesn't matter -- it's not *used* in the lambda either (as
mike pointed out, it's an argument to "reduce")

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->




More information about the Python-list mailing list