I have a dictionary of lists:
In [72]: params
Out[72]: {'a': [1, 2, 3], 'b': [5, 6, 7, 8]}
I may have more than two key/value pairs. I want to create a list of dictionaries which gives me all the possible combinations of the the lists corresponding to a and b:
e.g.
[{'a':1, 'b'=5},
{'a':1, 'b'=6},
{'a':1, 'b'=7},
...
{'a':3, 'b'=8},]
I can do this by hard coding the keys:
for a,b in itertools.product(*p.itervalues()):
print {'a':a, 'b':b}
But I don't want to hard code as
- I don't know how many key/value pairs there are and
- I don't necessarily know the names in advanced