python 中实现将两个列表合并为字典
001、方法1
>>> list1 = ["aaa", "bbb", "ccc"] >>> list2 = [100, 500, 300] >>> dict1 = dict(zip(list1, list2)) >>> dict1 {'aaa': 100, 'bbb': 500, 'ccc': 300}
002、方法2
>>> list1 = ["xxx", "zzz", "bbb"] >>> list2 = [300, 100, 500] >>> dict1 = dict() >>> for i in range(len(list1)): ... dict1[list1[i]] = list2[i] ... >>> dict1 {'xxx': 300, 'zzz': 100, 'bbb': 500}