Extract all possible combinations of unique elements in dict of lists

Question:

I have this input:

d = {'a': ['A', 'B', 'C'], 'b': ['A', 'B', 'C'], 'c': ['D', 'E'], 'd': ['E', 'F', 'G']}

How can I extract all the possible unique samplings per list?
One of the possible output is for example:

d = {'a': 'A', 'b': 'B', 'c': 'D', 'd': 'E'}

or

d = {'a': 'B', 'b': 'A', 'c': 'E', 'd': 'F'}

and so on..
Any idea?
Thank you

Asked By: Federico Livi

||

Answers:

This is what you are looking for

import itertools
keys, values = zip(*d.items())
permutations_dicts = [dict(zip(keys, v)) for v in itertools.product(*values)]
Answered By: Kryrena
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.