简体   繁体   中英

merging list of tuples and list and create dictionary

I have a list with a list of tuples and a list with 2 items. I Need to merge and create a new dictionary.

Here is an example: Input:

list1 = [('col1',20,30),('col2',40,50)]
list2 = ['name','age']

Desired result:

 output = {'col1':'name','col2':'age'}
output = {el1[0]: el2 for el1, el2 in zip(list1, list2)}

或对于旧版本的Python:

output = dict((el1[0], el2) for el1, el2 in zip(list1, list2))

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