Created
August 12, 2017 01:52
-
-
Save hughdbrown/2e6752ab64409cd85ce24199f40b8d89 to your computer and use it in GitHub Desktop.
Make a list of dictionaries from a dict of lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> parameters3 = { | |
... 'g': [100], | |
... 'h': [200, 201], | |
... 'i': [300, 301, 302], | |
... } | |
>>> | |
>>> from itertools import product | |
>>> def _exhaustive_list(parameters): | |
... keys, values = list(parameters.keys()), list(parameters.values()) | |
... return [ | |
... dict(zip(keys, comb)) | |
... for comb in product(*values) | |
... ] | |
... | |
>>> from pprint import pprint | |
>>> pprint(_exhaustive_list(parameters3)) | |
[{'g': 100, 'h': 200, 'i': 300}, | |
{'g': 100, 'h': 201, 'i': 300}, | |
{'g': 100, 'h': 200, 'i': 301}, | |
{'g': 100, 'h': 201, 'i': 301}, | |
{'g': 100, 'h': 200, 'i': 302}, | |
{'g': 100, 'h': 201, 'i': 302}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment