美文网首页
python两列表映射,元祖转化字典, 两字典合并

python两列表映射,元祖转化字典, 两字典合并

作者: 程序里的小仙女 | 来源:发表于2020-10-17 01:53 被阅读0次

    list1 = ["a", "b", "c","d"]
    list2 = [1,2,3,4]

    a = [ x for x in list1]

    生成器

    b = (x for x in list1)

    print(next(b))

    列表映射

    c= zip(list1,list2)
    print(c)
    for i in c:
    print(i)

    元祖转化字典

    tuplex = ((2, "w"),(3, "r"))
    print(dict((x, y) for x, y in tuplex))

    两字典合并

    dic1 = {2: 'w', 3: 'r'}
    dic2 = {6: 'rhiu', "wee": 'hui'}

    def Merge(dict1, dict2):
    res = {**dict1, **dict2}
    print(res)
    return res
    Merge(dic1,dic2)

    相关文章

      网友评论

          本文标题:python两列表映射,元祖转化字典, 两字典合并

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