5

So I would like to make a Python dictionary with the elements of one list as the keys and the list elements of another list as the values, is this possible?

So that:

list1 = ('red', 'blue', 'green', many more strings )
list2 = (1, 2, 3, many more values)

d = { list1[0:]: list2[0:] }

This obviously does not work, but something similar?

user1882385
  • 169
  • 2
  • 9

1 Answers1

19

You can do it like that:

>>> d = dict(zip(list1, list2))
{'blue': 2, 'green': 3, 'red': 1}
Nicolas
  • 5,583
  • 1
  • 25
  • 37
dugres
  • 12,613
  • 8
  • 46
  • 51
  • ok sorry, I really tried to find an answer but I guess I must've missed it! so funny that you can subtract reputation points, hilarious lol thank you for the answer! I will try this. – user1882385 Feb 16 '13 at 15:14