Converting to lists into one dictionary

Boudewijn Rempt boud at rempt.xs4all.nl
Mon Oct 4 13:26:00 EDT 1999


I was wondering whether it is possible to convert two lists into one
dictionary with one simple function: i.e., I've got a list of keys,
and a list of values like this:

list1=['a','b','c']
list2=['aaa','bbb','ccc']

and I want do something easy and speedy to these two lists that
will give me:

dict1={'a': 'aaa', 'b': 'bbb', 'c': 'ccc'}

preferably with the proviso that if there aren't enough values in 
list2, the dictionary is padded out with Nones. Is there something
built in, or do I have to loop trough list1 myself? I'm going to do
this an awful lot of times.

-- 

Boudewijn Rempt  | http://www.xs4all.nl/~bsarempt




More information about the Python-list mailing list