Merging two lists as a dictionary

Charles G Waldman cgw at fnal.gov
Tue Jul 20 23:13:16 EDT 1999


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

Unless I'm missing the point (which happens more than I'd like to
admit!)  I think what you're looking for is just:

dicp={}
for key,value in map(None,key_list,value_list):
    dict[key]=value





More information about the Python-list mailing list