python3 将两个列表生成一个字典

需求:

  存在两个list如下

  list1 = ["one", "two", "three"]

  list2 = ["1", "2", "3"]

  需要生成一个字典如下

  dict1 = {"one" : "1", "two" : 2, "three" : "3"}

 

解决方法:

  

dict4 = {m + ":" + n for m in list1 for n in list2}
print(dict4)

{'one:1', 'three:1', 'three:2', 'one:3', 'two:2', 'two:3', 'one:2', 'two:1', 'three:3'}

 

注意:

  拼接只对string有效,对int无效

posted @ 2019-03-08 15:07  huskiesir  阅读(2537)  评论(0编辑  收藏  举报