I have an arbitrary python dictionary x
such that the values of each key is itself a list. Here is an example:
x = {"first_name": ["Mahmoud", "Pei-chi"], "second_name": ["Abadi", "Yao"]}
Given x
I would like write a method that computes a list of dictionaries such that each dictionary has the same keys as x but the values are each combination of individual list element. So in this case, the result should be:
[{"first_name": "Mahmoud", "second_name": "Abadi"},
{"first_name": "Mahmoud", "second_name": "Yao"},
{"first_name": "Pei-chi", "second_name": "Abadi"},
{"first_name": "Pei-chi", "second_name": "Yao"}]
How can I do it? The dictionary x
may have any arbitrary number of keys with arbitrary names.