美文网首页
python列表装换为字典的方法

python列表装换为字典的方法

作者: coffeeaaaa | 来源:发表于2019-04-02 14:31 被阅读0次

将2个列表装换为字典的方法,比较适合key与value元素一一对应的情况下

        a = [1,2,3,4]

        b = [a,b,c,d]

        dict(zip(a,b))

二,嵌套列表转为字典的2种方法

    list = [[a,1],[b,2],[c,3],[d,4]]

    第一种方法

    dict(list)

    第二种方法

    dict = {}

    for i in list:

    dict[i[0]=i[1]]

相关文章

网友评论

      本文标题:python列表装换为字典的方法

      本文链接:https://www.haomeiwen.com/subject/tlhgbqtx.html