1、现在有两个列表,list1 = [‘key1 ‘,’key2 ‘,’key3 ‘ ]和list2 = [‘1’,’2’ ,’3’],把他们转为这样的字典: {‘key1 ‘:’1’,’key2’:’2 ‘,’key3’:’3 ‘ }

    1. list1 = ['key1','key2','key3']
    2. list2 = ['1','2','3']
    3. dict(zip(list1,list2 ) )
    4. {'key1':'1','key2':'2','key3':'3'}

    2、将嵌套列表转为字典,有两种方法,

    1. new_list= [['key1','value1'],['key2','value2'],['key3','value3']]
    2. dict(list)
    3. {'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}

    或者这样:

    1. new_list= [['key1','value1'],['key2','value2'],['key3','value3']]
    2. new_dict = {}
    3. for i in new_list:
    4. new_dict[i[0]] = i[1] #字典赋值,左边为key,右边为value
    5. new_dict
    6. {'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}

    https://blog.csdn.net/petib_wangwei/article/details/38685303