首页 > 代码库 > python中将两个list合并为字典

python中将两个list合并为字典

两个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();

 

python中将两个list合并为字典