list to dict

Yermat loic at fejoz.net
Wed Jun 16 10:30:42 EDT 2004


Bart Nessux wrote:
> Peter Hansen wrote:
> 
>> Bart Nessux wrote:
>>
>>> What is the easiest/fastest way to build a dictionary from a list? 
>>> The list contains 100,000 entries.
>>
>>
>>
>> A dictionary has key/value pairs.  How do you want to map
>> the elements of your list to this format?  In pairs, or
>> are you using them all as keys, or something else?
>>
>> -Peter
> 
> 
> 1 = book1
> 2 = book2
> 3 = book3
> etc...


 >>> dict(enumerate(['a','b','c']))
{0: 'a', 1: 'b', 2: 'c'}
 >>>




More information about the Python-list mailing list