problem of converting a list to dict

John Machin sjmachin at lexicon.net
Wed Jan 9 15:01:30 EST 2008


On Jan 10, 6:52 am, "Reedick, Andrew" <jr9... at ATT.COM> wrote:
> > -----Original Message-----
> > From: python-list-bounces+jr9445=att.... at python.org [mailto:python-
> > list-bounces+jr9445=att.... at python.org] On Behalf Of Fredrik Lundh
> > Sent: Wednesday, January 09, 2008 2:39 PM
> > To: python-l... at python.org
> > Subject: Re: problem of converting a list to dict
>
> > Louis.Soni... at gmail.com wrote:
>
> > >> to see what's going on on your machine, try printing "a" after the
> > >> split, but before you use it to populate the dictionary.
>
> > > 'print a' works
>
> > so what does it tell you?
>
> A bigger hint:
>         a=i.split('=')
>         print "'%s' splits into " % (i), a

consider:
(1) using %r instead of '%s'
(2) omitting the redundant space after 'into'
(3) losing the redundant () around i


>         assert len(a) == 2
>         mydict[a[0]]=a[1]




More information about the Python-list mailing list