Return a reference to unpacked dictionary in Python

33 views Asked by At

There is a common way to pass arguments in Python like this:

def foo(a1, a2):
    print(a1, a2)
    
def my_dict():
    return {'a1': 4, 'a2':5}

foo(**my_dict())

...

4 5

But now I want to move the asterisks inside my_dict function:

def foo(a1, a2):
    print(a1, a2)
    
def my_dict():
    return **{'a1': 4, 'a2':5}

foo(my_dict())

...

SyntaxError: invalid syntax

Is there a way to achieve such behavior in Python? I am dealing with third-party code and can modify my_dict function, but can't modify foo(my_dict()) call.

0

There are 0 answers