Newbie question...

Mike 'Cat' Perkonigg blablu at gmx.net
Thu Sep 28 03:28:18 EDT 2000


ivnowa at hvision.nl (Hans Nowak) wrote in <39D1FC71.6768 at hvision.nl>:

>y must have an initial value... try inserting  y = 0  before the for.
>Aside from that, you probably want to use args.values() rather than
>args.keys().
>
>This won't work for your second line (good="a", etc) though, because it
>uses strings for values, and y is initialized as an integer.
>
>If you want a more generic function, you could try:
>
>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.

Regards,
Mike



More information about the Python-list mailing list