dictionary - Multiply Values of two dictionaries, while appending the Keys in Python -


i have 2 dictionaries. 1 contain different products , each demand them. other contains temporal demand distribution values in multiple days.

i need append keys of both dictionaries, , multiply demand temporal demand distribution.

sample data (real data larger):

 dict = {'s-nsw-bac-eng': 15, 's-nsw-bac-fbe': 30}   temporal_demand_distibution = {-60: 0.001187, -59: 0.001354} 

the expected output like:

resulting_dict = {'s-nsw-bac-eng:-60': 0.001187*15, 's-nsw-bac-eng:-59': 0.001354*15, 's-nsw-bac-fbe:-60': 30*0.001187, 's-nsw-bac-fbe:-59': 30*0.001354} 

the values result of multiplication , not multiplication itself.

i know it's bad post question without sample code, have no idea how achieve this.

use double loop , combine keys , values:

from pprint import pprint  dict = {'s-nsw-bac-eng': 15, 's-nsw-bac-fbe': 30} temporal_demand_distribution = {-60: 0.001187, -59: 0.001354}  result_dict = {} key, value in dict.items():   key2, value2 in temporal_demand_distribution.items():     result_dict["{}:{}".format(key, key2)] = value * value2  pprint(result_dict) 
{'s-nsw-bac-eng:-59': 0.020309999999999998,  's-nsw-bac-eng:-60': 0.017804999999999998,  's-nsw-bac-fbe:-59': 0.040619999999999996,  's-nsw-bac-fbe:-60': 0.035609999999999996} 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -