Mike 'Cat' Perkonigg
blablu at gmx.net
Thu Sep 28 09:28:18 CEST 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
>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:
> return reduce(lambda x, y, a=args: x+y, args.values())
>>>> print adder3(good=1, bad=2, ugly=3)
>>>> print adder3(good="a", bad="b", ugly="c")
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.
More information about the Python-list