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
本文来自博客园,作者:Titen,转载请注明原文链接:https://www.cnblogs.com/chengxiazuohua/p/17358785.html