Python中是否有任何内置函数将两个列表合并为一个字典?像:
combined_dict = {}
keys = ["key1","key2","key3"]
values = ["val1","val2","val3"]
for k,v in zip(keys,values):
combined_dict[k] = v
其中:
keys
充当包含密钥的列表。
values
充当包含值
有一个名为array_combine的功能可以达到这个效果。
答案 0 :(得分:7)
似乎这应该有效,但我猜它不是一个单一功能:
dict(zip(["key1","key2","key3"], ["val1","val2","val3"]))
从这里开始:How do I combine two lists into a dictionary in Python?