Python dict from two lists

Beautiful Python one liner that creates a dictionary from two lists, using one list as the dictionary keys and the other as the dictionary values.

>>> key_list = ['x', 'y', 'z']
>>> value_list = [0, 1, 2]
>>> combined_dict = dict(zip(key_list, value_list))
>>> print combined_dict
{'x': 0, 'y': 1, 'z': 2}
  • http://www.virtual-force.com/services/web-design WordPress Theme Development

    These two lists are awesome and I wan tto congratulate the author for such a wonderful write.