Merge two lists,one as keys, one as values, into a dict in Python
本问题已经有最佳答案,请猛点这里访问。
python中是否有将两个列表合并为dict的内置函数?像:
1 2 3 4 5 6 7 8 | combined_dict = {} keys = ["key1","key2","key3"] values = ["val1","val2","val3"] for k,v in zip(keys,values): combined_dict[k] = v |
在哪里?
有一个名为array_combine的函数可以实现这种效果。
虽然我想这不是一个单一的功能,但这似乎是可行的:
1 | dict(zip(["key1","key2","key3"], ["val1","val2","val3"])) |
从这里:如何在Python中将两个列表组合成一个字典?