Help with creating a dict from list and range

James Stroud jstroud at mbi.ucla.edu
Fri Oct 14 22:06:35 EDT 2005


Could be even simpler since enumerate creates tuples anyway:

dct = dict(x for x in enumerate(description))

James

On Friday 14 October 2005 08:37, Steve Holden wrote:
>  >>> dct = dict((x[1], x[0]) for x in enumerate(description))
>  >>> dct
>
> {'second': 1, 'third': 2, 'first': 0}
>
> regards
>   Steve
> --
> Steve Holden       +44 150 684 7255  +1 800 494 3119
> Holden Web LLC                     www.holdenweb.com
> PyCon TX 2006                  www.python.org/pycon/

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list