Basically what I am looking for is the equivalent of itertools.product
but for dict
s.
For example, say I want to test a function for all combinations of its keyword arguments, I would like to pass lists of permissible values for each keyword argument and then get back a list of dicts.
kwargs_options = {"debug": ["on", "off"], "locale":["de_DE", "en_US", "fr_FR"]
expected ouput:
[{'debug': 'on', 'locale': 'de_DE'},{'debug': 'on', 'locale': 'en_US'},{'debug': 'on', 'locale': 'fr_FR'},{'debug': 'off', 'locale': 'de_DE'},{'debug': 'off', 'locale': 'en_US'},{'debug': 'off', 'locale': 'fr_FR'}]
In order to have a similar API to itertools.product
this should return an iterator, which can then be wrapped with a call to list(...)
if desired.
Example call:
list(dictproduct(kwargs_options}))
This is similar to Combinations from dictionary with list values using Python but returns a list of two-element dicts rather than two single-element dicts.