How to itereate over multiple parameter settings

I’m sure everyone knows this scenario: you have different parameter settings that you want to evaluate, so you create a simple for-loop and all is good. But then you wonder, wouldn’t it be interesting to also examine the effect of another parameter variation? So you start a nested for-loop. But what if want to include even more? It quickly becomes cumbersome and confusing. itertools.product comes to the rescue!

config_options = {
    'version': [1, 2],
    'some_option': ['a', 'b', 'c'],
    'some_flag': [False],

import itertools
keys, values = zip(*config_options.items())
cases = [dict(zip(keys, v)) for v in itertools.product(*values)]

for case in cases:
>>> {'version': 1, 'some_option': 'a', 'some_flag': False}
{'version': 1, 'some_option': 'b', 'some_flag': False}
{'version': 1, 'some_option': 'c', 'some_flag': False}
{'version': 2, 'some_option': 'a', 'some_flag': False}
{'version': 2, 'some_option': 'b', 'some_flag': False}
{'version': 2, 'some_option': 'c', 'some_flag': False}

Ah, much better! :nerd: