0

I would like to pass an undefined number of optional arguments to a function. The optional arguments are stored a priori in a dictionary.

As an example:

def f(a=0, b=0, c=0):
    return a

my_args = {'a':5, 'b':3}

print(f(my_args))

The expected output would be 5, however it is {'a':5, 'b':3}

Vincent Savard
  • 34,979
  • 10
  • 68
  • 73
mat
  • 2,412
  • 5
  • 31
  • 69

1 Answers1

1

You need to unpack the dict:

print(f(**my_args))
user2390182
  • 72,016
  • 6
  • 67
  • 89