Dict within a dict

Advertisements

I have the following data structure and written code:

alpha = {'Jan': [1,2,3]}
beta = {'Jan': [4,5,6]}
carter = {'Jan': ['boo', 'fee', 'lee']}

delta = {month: {month: [b-a for (b, a) in zip(be, al)]
                for (month, be), (month, al) in zip(beta.items(), alpha.items())}
        for month, ca in carter.items()}

print(delta)
{'Jan': {'Jan': [3, 3, 3]}}

However, I want the result to look like this:

{'Jan': {'boo': 3, 'fee': 3, 'lee': 3}

what is the right way to write this to get desired result?

>Solution :

Assuming you meant your output as {'Jan': {'boo': 3, 'fee': 3, 'lee': 3}}:

delta = {month: 
            {ca : (b - a) for ca, b, a in zip(carter[month], beta[month], alpha[month])} 
            for month in carter.keys()}

Leave a ReplyCancel reply