-1

As the question says, I have two lists that look like this:

list1 = ["key1", "key2"]
list2 = ["value1", "value2"]

I would like to create a dictionary like this:

dict1 = {"key1": "value1" , "key2" : "value2"}

Is there are an easy way to do so?

2 Answers2

0
my_dict = dict(zip(list1, list2))
Sazzy
  • 1,924
  • 3
  • 19
  • 27
0

A dictionary comprehension is perfect for this:


dict1 = {k: v for k, v in zip(list1, list2)}

Edit: it seems there is an even shorter solution, as per Sazzy's answer :)

ElRudi
  • 2,122
  • 2
  • 18
  • 33