Nelly Louis
Nelly Louis

Reputation: 167

How to create a dictionary from several lists in Python

I want to create a dictionary from several lists. For example:

list1=[11, 12, 13, 14]
list2=[a, b, c, d]
list3=[e, f, g, h]

and the result should be:

dict={11: [a,e], 12:[b,f], 13:[c,g], 14:[d,h]}

Thanks

Upvotes: 1

Views: 69

Answers (1)

goodvibration
goodvibration

Reputation: 6206

Like so:

obj = {}
for x,y,z in zip(list1,list2,list3):
    obj[x] = [y,z]

Upvotes: 2

Related Questions