Combine two lists, one as keys, one as values, in a dict in Python

Is there a built-in function in Python that combines two lists in a dict? How:

combined_dict = {} keys = ["key1","key2","key3"] values = ["val1","val2","val3"] for k,v in zip(keys,values): combined_dict[k] = v 

Where:

keys acts like a list containing keys.

values acts like a list containing values

There is an array_combine function that achieves this effect.

+4
source share
1 answer

This seems to work, although I think this is not one single function:

 dict(zip(["key1","key2","key3"], ["val1","val2","val3"])) 

from here: How to combine two lists into a dictionary in Python?

+7
source

Source: https://habr.com/ru/post/1414066/


All Articles