list to dict

Larry Bates lbates at swamisoft.com
Wed Jun 16 10:44:55 EDT 2004


If the keys are just indexes that you would
use in the dictionary, you don't need a
dictionary at all.  Just index into the list.

list[0]->'book1'
list[1]->'book2'
list[2]->'book3'

You will need to deal with the indexes beginning
at zero (not 1) or put None in list[0] an then
don't reference it.

HTH,
Larry Bates
Syscon, Inc.

"Bart Nessux" <bart_nessux at hotmail.com> wrote in message
news:capk64$8ku$1 at solaris.cc.vt.edu...
> 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...





More information about the Python-list mailing list