list to dict

Yermat loic at yermat.net1.nerim.net
Thu Jun 17 13:26:00 EDT 2004


Denis S. Otkidach a écrit :

> On Wed, 16 Jun 2004, Yermat wrote:
> 
> Y> > What is the easiest/fastest way to build a dictionary from
> Y> a list? The
> Y> > list contains 100,000 entries.
> Y> >
> Y> > Thanks,
> Y> > Bart
> Y>
> Y>  >>> dict([(1,'a'),(2,'b')])
> Y> {1: 'a', 2: 'b'}
> Y>
> Y> list of tuples -> dict !
> 
> But unfortunately list({1: 'a', 2: 'b'}) -> [1, 2].
> 

 >>> {1: 'a', 2: 'b'}.values()
['a', 'b']
 >>> {1: 'a', 2: 'b'}.items()
[(1, 'a'), (2, 'b')]
 >>> {1: 'a', 2: 'b'}.keys()
[1, 2]

The documentation worst to be read...

-- 
Yermat




More information about the Python-list mailing list