python 两个list合并成一个dict的方法
摘要:
def meshList(): list2 = [1, 2, 3, 4, 5 ];list3 = ["a", "b", "c", "d","e"]; dict={}; length=len(list2);
def meshList(): list2 = [1, 2, 3, 4, 5 ]; list3 = ["a", "b", "c", "d","e"]; dict={}; i=0; length=len(list2); while i<length: 'dict[list2[i]]=list3[i];这种方法也可以' dit={list2[i]:list3[i]}; dict.update(dit); i+=1; return dict; if __name__ == '__main__': print Run();
上面是不使用python的内置函数的情况下,还有一种方式,使用py的内置函数:
dict(zip(file, titles))
如图所示,完成:
本文由 帝一博客 原创发布。用户在本站发布的原创内容(包括但不仅限于回答、文章和评论),著作权均归用户本人所有。独家文章转载,请联系邮箱:17762131@qq.com。获得授权后,须注明本文地址: https://bubukou.com/pythonpachong/1457.html
相关文章
图文资讯
-
【原创】python_docx制作word文档实例demo
2019-10-29 16:15
-
python遍历字典dict
2019-09-22 12:05
-
python 两个list合并成一个dict的方法
2019-09-22 11:56
-
【原创】python 爬取wowo扣扣爬虫代码
2019-09-05 14:46
-
windows 怎么安装 python 的 win32 wi...
2019-08-10 18:15
-
[原创]python 证书验证http 304问题
2019-08-07 14:02
-
【原创】python 爬取小清新唯美图片
2019-07-18 22:19
-
Python简单计算文件MD5值的方法示例
2019-07-18 22:13
-
从零开始Python对redis作为消息队列的使用
2019-07-10 08:37
-
如何安装python到setuptools、pip工具安装
2019-07-10 07:52
网友留言评论