How can I make a list of dictionaries according to the Cartesian product of values in a source dictionary (“explode” the dictionary)?
I think you want the Cartesian product, not a permutation, in which case itertools.product can help: >>> from itertools import product >>> d = {‘Color’: [‘Red’, ‘Yellow’], ‘Size’: [‘Small’, ‘Medium’, ‘Large’]} >>> [dict(zip(d, v)) for v in product(*d.values())] [{‘Color’: ‘Red’, ‘Size’: ‘Small’}, {‘Color’: ‘Red’, ‘Size’: ‘Medium’}, {‘Color’: ‘Red’, ‘Size’: ‘Large’}, {‘Color’: ‘Yellow’, ‘Size’: ‘Small’}, {‘Color’: … Read more