5

Is there any build-in function in Python that merges two lists into a dict? Like:

combined_dict = {}

keys = ["key1","key2","key3"] 

values = ["val1","val2","val3"]

for k,v in zip(keys,values):
    combined_dict[k] = v

Where:

keys acts as the list that contains the keys.

values acts as the list that contains the values

There is a function called array_combine that achieves this effect.

xiaohan2012
  • 8,986
  • 20
  • 64
  • 99

1 Answers1

8

Seems like this should work, though I guess it's not one single function:

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

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

Community
  • 1
  • 1
TankorSmash
  • 11,649
  • 6
  • 62
  • 103