Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. MC={'рыба': ['100'], 'мясо': ['120']}
  2. RC={'рыба': ['3'], 'мясо': ['2']}
  3.  
  4. GC={'мясо': 240, 'рыба': 300}
  5.  
  6. CG = {}
  7.  
  8. for key in MC.keys():
  9. try:
  10. CG[key] = [str(int(count) * int(RC[key][index])) for index, count in enumerate(MC[key])]
  11. except KeyError:
  12. CG[key] = MC[key]
  13.  
  14. In [8]: MC={'рыба': ['100'], 'мясо': ['120']}
  15. ...: RC={'рыба': ['3'], 'мясо': ['2']}
  16. ...:
  17.  
  18. In [9]: foo = lambda dct_1, dct_2: {key: int(dct_2[key][0]) * int(dct_1[key][0]) for key in dct_2}
  19.  
  20. In [10]: foo(MC, RC)
  21. Out[10]: {'мясо': 240, 'рыба': 300}
  22.  
  23. import itertools, operator, functools
  24.  
  25. MC = {'рыба': ['100'], 'мясо': ['120', '5', '6']}
  26. RC = {'рыба': ['3'], 'мясо': ['2']}
  27. CC = {'рыба': ['2'], 'мясо': ['1', '3'], 'квас': ['3']}
  28.  
  29. c_dicts = MC, RC, CC
  30.  
  31. GC = {k: [functools.reduce(operator.mul, map(int, nums), 1)
  32. for nums in itertools.zip_longest(*[dt.get(k, [1]) for dt in c_dicts], fillvalue=1)]
  33. for k in set(itertools.chain(*c_dicts))}
  34.  
  35. # {'квас': [3], 'мясо': [240, 15, 6], 'рыба': [600]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement