When trying to find optimal parameters for some program, it would be handy if the code could be automatically executed for all possible values of a parameter in a certain range, without having to manually add for
loops everywhere. Let's explain:
Let prms
be a dict of parameters. If each value of this dict
is not a list, then the following code should be normally executed, like this:
prms = dict()
prms['param1'] = 3
prms['param2'] = 4
prms['param3'] = -17
do_something(prms)
But if each parameter is a list, then the program should be re-executed for each value of the list. Example:
prms = dict()
prms['param1'] = [3, 7]
prms['param2'] = [4]
prms['param3'] = [-17, 2]
should give:
p = dict()
for p['param1'] in prms['param1']:
for p['param2'] in prms['param2']:
for p['param3'] in prms['param3']:
do_something(p)
Is there a programming pattern / nice way to do this?