I have sets of values that I want to apply as parameters to a function:
params = {
'a': [1, 2, 3],
'b': [5, 6, 7],
'x': [None, 'eleven', 'f'],
# et cetera
}
I want to run myfunc()
with all possible combinations, so myfunc(a=1, b=5, x=None ...)
, myfunc(a=2, b=5, x=None ...)
... myfunc(a=3, b=7, x='f' ...)
. Is there something (for example in itertools
) that can help? I thought about using itertools.product()
but that doesn't keep the names of the parameters and just gives me tuples of the combinations.
itertools.product()
returns the parameters in a different order than you have the keys, which would lead to a mismatch. – Fingerprint