python中将两个list合并为字典

时间:2022-05-20 21:03:36

两个list合并为字典的代码如下:

def Run():
    list2 = [1, 2, 3, 4, 5 ];
    list3 = ["a", "b", "c", "d","e"];
    dict={};
    i=0;
    length=len(list2);    
    while i<length:
        'dict[list2[i]]=list3[i];这种方法也可以'
        dit={list2[i]:list3[i]};
        dict.update(dit);
        i+=1;
    return dict;

if __name__ == '__main__':
    print Run();