Cartesian product of dictionaries

Viewed 823

I am trying to write some python code to get the following output, all permutations. Values of region and gender are probabilities, result reflects a product of given events combination.

It seems that can be achieved by using itertools and apply, but I'm not quite sure about the specific implementations.

Inputs:

region = {'east': 0.5, 'north': 0.20, 'south': 0.10, 'west': 0.20}
gender = {'female': 0.70, 'male': 0.30}

Desired output:

result = {('east','female'):0.35, 
('east','male'):0.15,
('north','female'):0.14,
('north','male'):0.06,
('south','female'):0.07,
('south','male'):0.03,
('west','female'):0.14,
('west','male'):0.06}
2 Answers
Related