a dictionary from a list
Terry Hancock
hancock at anansispaceworks.com
Sat Jun 25 04:02:03 EDT 2005
On Friday 24 June 2005 05:26 pm, infidel wrote:
> dict((x, None) for x in alist)
or if you want it to run in 2.3 (before "generator
expressions"):
dict( [(x,None) for x in alist] )
Before the dict constructor, you needed to do this:
d={}
for key in alist:
d[key]=None
which is still only 3 lines and will run
in Python 1.5, IIRC.
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list