Newbie question...

Fredrik Lundh effbot at
Thu Sep 28 22:03:38 CEST 2000

> >>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"

> >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.

> 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)

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")


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list