Skip to main content
added 399 characters in body
Source Link

The previous answer was pretty goodTo expand the dictionary into a list, but it had some unneeded steps as there is noyou need to splitbuild the dict up earlierproduct from all possible params.

You can use itertools.product to build the product with all values from the dictionary config_overrides.

The resulting list of lists has all combinations of values from config_overrides and each items length is equal to len(config_overrides.keys())

Therefore we can use zip to attach each key to the position of a param in your product.

With the list of pairs, we can now easily create a dictionary.

For the sake of one liners here my version:

from itertools import product
experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]

The previous answer was pretty good, but it had some unneeded steps as there is no need to split the dict up earlier.

For the sake of one liners here my version:

from itertools import product
experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]

To expand the dictionary into a list, you need to build the product from all possible params.

You can use itertools.product to build the product with all values from the dictionary config_overrides.

The resulting list of lists has all combinations of values from config_overrides and each items length is equal to len(config_overrides.keys())

Therefore we can use zip to attach each key to the position of a param in your product.

With the list of pairs, we can now easily create a dictionary.

For the sake of one liners here my version:

from itertools import product
experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]
Remove some fluff move the point this answer makes to the top of the answer.
Source Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

Why the lastThe previous answer was pretty good, but it had some unneeded steps as there is no need to split the dict up earlier. For

For the sake of one liners here my version:

>>>fromfrom itertools import product
>>>experimentsexperiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]

The main difference here is that there is no need to split the dict up earlier.

Why the last answer was pretty good, it had some unneeded steps there. For the sake of one liners here my version:

>>>from itertools import product
>>>experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]

The main difference here is that there is no need to split the dict up earlier.

The previous answer was pretty good, but it had some unneeded steps as there is no need to split the dict up earlier.

For the sake of one liners here my version:

from itertools import product
experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]
Source Link

Why the last answer was pretty good, it had some unneeded steps there. For the sake of one liners here my version:

>>>from itertools import product
>>>experiments = [dict(zip(config_overrides.keys(), value)) for value in product(*config_overrides.values())]

The main difference here is that there is no need to split the dict up earlier.