Creating a dictionary from a dict & list

Dea*_*pha 0 python dictionary

I have a dictionary & a list as follows.

>>> new_coins
{'main': '100', 'single': '10'}
>>> get_snip_priority('prod-oregon')
['prod-singapore', 'prod-delhi']
Run Code Online (Sandbox Code Playgroud)

I need the best efficient way to create a dictionary using the above 2 data structs as follows:

{
main : { 
        'prod-singapore': 100, # 100 is the value of main 
        'prod-delhi': 100 }, 
single: {
        'prod-singapore': 10, # 10 is the value of static 
        'prod-delhi': 10 }, 
Run Code Online (Sandbox Code Playgroud)

can some one help

Hen*_*Yik 5

You can use nested dict comprehension:

new_coins = {'main': '100', 'single': '10'}

cities = ['prod-singapore', 'prod-delhi']

new = {key:{city:value for city in cities} for key,value in new_coins.items()}

print (new)

#{'main': {'prod-singapore': '100', 'prod-delhi': '100'}, 'single': {'prod-singapore': '10', 'prod-delhi': '10'}}
Run Code Online (Sandbox Code Playgroud)