Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dict1 = {'a': {'a-g': [[[1, 2, 3, 4]], [[1, 2]]],
- 'a-w': [True, False, True],
- 'a-x': [[1, 2, 3], [4, 5]],
- 'a-y': [1, 5, 7],
- 'a-z': True},
- 'b': {'b-x': [1, 4, 5],
- 'b-y': 3}}
- dict2 = {'alpha': 'a-w', 'beta': 'b-y', 'delta': 'a-x', 'gamma': 'a-w', 'eta': 'a-g'}
- arglist = []
- vallist = []
- for key, val in dict2.items():
- arglist.append(key)
- outkey = val[:val.find("-")]
- vallist.append(dict1[outkey][val])
- from collections.abc import Iterable
- from itertools import product
- out = list(product(*[v if isinstance(v, Iterable) else [v] for v in vallist]))
- finallist = []
- for x in out:
- tempdict = {}
- count = 0
- for arg in range(len(x)):
- tempdict[arglist[count]] = x[count]
- count += 1
- finallist.append(tempdict)
- for x in finallist:
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment