Help with creating a dict from list and range

Scott David Daniels scott.daniels at acm.org
Sat Oct 15 09:20:03 EDT 2005


James Stroud wrote:
> On Friday 14 October 2005 08:37, Steve Holden wrote:
>> >>> dct = dict((x[1], x[0]) for x in enumerate(description))

To make the code a breath more obvious:
>>> dct = dict((name, seq) for seq, name in enumerate(description))
has the same results.

>> >>> dct
>>
>>{'second': 1, 'third': 2, 'first': 0}
>>


-- 
-Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list