Reikriam

Untitled

Jul 29th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. dict1 = {'a': {'a-g': [[[1, 2, 3, 4]], [[1, 2]]],
  2. 'a-w': [True, False, True],
  3. 'a-x': [[1, 2, 3], [4, 5]],
  4. 'a-y': [1, 5, 7],
  5. 'a-z': True},
  6. 'b': {'b-x': [1, 4, 5],
  7. 'b-y': 3}}
  8.  
  9. dict2 = {'alpha': 'a-w', 'beta': 'b-y', 'delta': 'a-x', 'gamma': 'a-w', 'eta': 'a-g'}
  10.  
  11. arglist = []
  12. vallist = []
  13. for key, val in dict2.items():
  14. arglist.append(key)
  15. outkey = val[:val.find("-")]
  16. vallist.append(dict1[outkey][val])
  17.  
  18. from collections.abc import Iterable
  19. from itertools import product
  20.  
  21. out = list(product(*[v if isinstance(v, Iterable) else [v] for v in vallist]))
  22.  
  23. finallist = []
  24. for x in out:
  25. tempdict = {}
  26. count = 0
  27. for arg in range(len(x)):
  28. tempdict[arglist[count]] = x[count]
  29. count += 1
  30. finallist.append(tempdict)
  31.  
  32. for x in finallist:
  33. print(x)
Advertisement
Add Comment
Please, Sign In to add comment