zip函数组装字典和列表

zip:字面意思就是打包的意思,目的也是打包

组装列表:

def get_dict(a:list,b:list):
    d = list(zip(a,b))
    return d


if __name__ == '__main__':
    # print(time_specific())
    list1 = [1,2,3]
    list2 = [4,5,6]
    print(get_dict(list1,list2))

结果:

D:\Python\python.exe D:\highway\api\highway_apiframe\commons\wz.py 
[(1, 4), (2, 5), (3, 6)]

进程已结束,退出代码0

 

组装字典:

def get_dict(a:list,b:list):
    d = dict(zip(a,b))
    return d


if __name__ == '__main__':
    # print(time_specific())
    list1 = [1,2,3]
    list2 = [4,5,6]
    print(get_dict(list1,list2))

结果:

D:\Python\python.exe D:\highway\api\highway_apiframe\commons\wz.py 
{1: 4, 2: 5, 3: 6}

进程已结束,退出代码0

 

posted on 2023-04-27 14:15  Titen  阅读(5)  评论(0编辑  收藏  举报

导航