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   Titen  阅读(6)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
历史上的今天:
2022-04-27 2--api接口关联(取值和用值)易错点
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示