argument matching question

Leif K-Brooks eurleif at ecritters.biz
Thu Aug 25 21:20:57 EDT 2005


Learning Python wrote:
> A code like this:
> 
> def adder(**varargs):
>       sum=varargs[varargs.keys()[0]]
>       for next in varargs.keys()[1:]:
>                 sum=sum+varargs[next]
>       return sum
> 
> print adder( "first","second",'third')
> 
> How to pass arguments to a functions that use dictionary collection?

Like adder(foo="bar", bar="baz"), but I think you really want a function
like this:

def adder(*args):
    sum = args[0]
    for value in args[1:]:
        sum += value
    return sum



More information about the Python-list mailing list