Looking for some help in creating a dictionary using 3 python lists
a = ['alpha','bravo','charlie']
b = ['a','b','c']
c = [1,2,3]
output:
{'alpha': {'letter': 'a', 'number': 1},
'bravo': {'letter': 'b', 'number': 2},
'charlie': {'letter': 'c', 'number': 3}}
I tried something like this. This may be close, but needs some tweaking:
{k: dict(v) for k,v in zip(a, zip(('letter', b),('number', c)))}
>Solution :
The dict
comprehension can zip
all three iterables at once, and just include a dict
literal for the sub-dict
:
{k: {'letter': let, 'number': num} for k, let, num in zip(a, b, c)}