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无效