I want to do something like this:
dict = {'a':1, 'b':2}
def f(dict):
return a + b
I am imagining something like Ruby's method missing, where I somehow make python search for any undefined terms as a string keyword in 'dict' before throwing an error. Is this possible?
EDIT: This is not a duplicate of the link above, but I need to clarify my question. Python keyword args allows for:
dict = {'a':1, 'b':2}
def f1(a, b):
return a + b
f1(**dict) # use ** to unpack
# Or use ** to pack args
def f2(**kwargs):
return kwargs['a'] + kwargs['b']
f2(a=1, b=2)
What I am wondering about is exactly this:
def f(dict):
return arbitrary1 + arbitrary2
f({'arbitrary1':1, 'arbitrary2':2})
Is there anyway I can make this work? I want to unpack the dict, but I don't want to have to change the method signature to match the contents of the dictionary.