bsneddon wrote:
> This seemed to work for me if you are using 2.4 or greater and
> like list comprehension.
dict([ tuple(a.split("=")) for a in mylist[1:-1]])
> {'mike': 'manager', 'paul': 'employee', 'tom': 'boss'}
>
> should be faster than looping
That's what he's doing (well, a generator
TECTED]
> > Subject: Re: problem of converting a list to dict
>
> > On Jan 10, 6:52 am, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
>
> > > A bigger hint:
> > > a=i.split('=')
> > > print "'%s' s
gt; To: python-list@python.org
> > Subject: Re: problem of converting a list to dict
> >
> > On Jan 10, 6:52 am, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > >
> > > A bigger hint:
> > > a=i.split('=')
> > >
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of John Machin
> Sent: Wednesday, January 09, 2008 3:02 PM
> To: python-list@python.org
> Subject: Re: problem of converting a list to dict
>
> On Jan 10, 6:52 am, &
On Jan 9, 3:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> > I'd like to remove the first and the last item as they are irrevalent,
> > and convert it to the dict:
> > {'tom':'boss','mike':'manager','paul':'employee'}
>
> > I
On Jan 10, 7:12 am, Tim Chase <[EMAIL PROTECTED]> wrote:
> > mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> > I'd like to remove the first and the last item as they are irrevalent,
> > and convert it to the dict:
> > {'tom':'boss','mike':'manager','paul':'employee'}
>
> > I
> mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> I'd like to remove the first and the last item as they are irrevalent,
> and convert it to the dict:
> {'tom':'boss','mike':'manager','paul':'employee'}
>
> I tried this but it didn't work:
>
> mydict={}
> for i in mylist[
[EMAIL PROTECTED]
> > Subject: Re: problem of converting a list to dict
>
> > [EMAIL PROTECTED] wrote:
>
> > >> to see what's going on on your machine, try printing "a" after the
> > >> split, but before you use it to populate the dic
oops, it seems there are other 'meaningless' item, which actually
caused the problem
Thanks for helps
--
http://mail.python.org/mailman/listinfo/python-list
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Fredrik Lundh
> Sent: Wednesday, January 09, 2008 2:39 PM
> To: python-list@python.org
> Subject: Re: problem of converting a list to dict
>
> [EMAIL PROTECTED] wrot
On Jan 10, 5:56 am, [EMAIL PROTECTED] wrote:
> Hi pals
>
> I have a list like this
>
> mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> I'd like to remove the first and the last item as they are irrevalent,
> and convert it to the dict:
> {'tom':'boss','mike':'manager','paul'
[EMAIL PROTECTED] 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?
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 9, 3:05 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I have a list like this
>
> > mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> > I'd like to remove the first and the last item as they are irrevalent,
> > and convert it to the dict:
>
that's very strange...
the list I give here is almost same as the real list, except for the
length.
Thanks Marc, I'll go check what's wrong elsewhere
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I have a list like this
>
> mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> I'd like to remove the first and the last item as they are irrevalent,
> and convert it to the dict:
> {'tom':'boss','mike':'manager','paul':'employee'}
>
> I tried thi
On Wed, 09 Jan 2008 10:56:36 -0800, Louis.Soninhu wrote:
> Hi pals
>
> I have a list like this
>
> mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> I'd like to remove the first and the last item as they are irrevalent,
> and convert it to the dict:
> {'tom':'boss','mike':
Hi pals
I have a list like this
mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
I'd like to remove the first and the last item as they are irrevalent,
and convert it to the dict:
{'tom':'boss','mike':'manager','paul':'employee'}
I tried this but it didn't work:
mydict={}
fo
17 matches
Mail list logo