a dictionary from a list

Benji York benji at benjiyork.com
Fri Jun 24 18:29:05 EDT 2005


David Bear wrote:
> Assume I have a list object called 'alist'.
> 
> Is there an easy way to create a dictionary object with the members of
> 'alist' being the keys in the dictionary, and the value of the keys set to
> null?

You mean None, right?  :)

 >>> a_list = [1, 2, 3, 'a', 'b', 'c']
 >>> dict.fromkeys(a_list)
{'a': None, 1: None, 2: None, 3: None, 'c': None, 'b': None}
--
Benji York



More information about the Python-list mailing list