简体   繁体   中英

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

Like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM