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

 

posted @ 2017-01-19 19:56  浮尘~若梦  阅读(2786)  评论(1编辑  收藏  举报