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
  • 32,695
  • 10
  • 65
  • 72
mat
  • 2,141
  • 4
  • 21
  • 60

1 Answers1

1

You need to unpack the dict:

print(f(**my_args))
user2390182
  • 67,685
  • 6
  • 55
  • 77