All combinations of dictionary values

suggest change
options = {
	"x": ["a", "b"],
	"y": [10, 20, 30]
}

Given a dictionary such as the one shown above, where there is a list representing a set of values to explore for the corresponding key. Suppose you want to explore "x"="a" with "y"=10, then "x"="b" with "y"=10, and so on until you have explored all possible combinations.

You can create a list that returns all such combinations of values using the following code.

This gives us the following list stored in the variable combinations:

[{'x': 'a', 'y': 10},
 {'x': 'b', 'y': 10},
 {'x': 'a', 'y': 20},
 {'x': 'b', 'y': 20},
 {'x': 'a', 'y': 30},
 {'x': 'b', 'y': 30}]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents