Merging two lists as a dictionary

David Arnold arnold at dstc.edu.au
Tue Jul 20 23:23:51 EDT 1999


-->"Chris" == Chris Frost <chris at frostnet.advicom.net> writes:

  Chris> I have two lists and would like to merge them into a
  Chris> dictionary, with one list forming the keywords and the other
  Chris> the values in the dictionary. How c= ould this be done?
  Chris> "map(None, keyword_list, value_list)" looked great, but it
  Chris> returns a list of pairs (I'd like to be able to specify
  Chris> values according to keywords...).

it's ugly, but ...

reduce(lambda d,i,setitem=operator.__setitem__: setitem(d,i[0],i[1]) or d, map(None, keyword_list, value_list), {})




d




More information about the Python-list mailing list