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={}
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:
[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 this but it
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
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:
[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?
/F
--
http://mail.python.org/mailman/listinfo/python-list
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:
-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] wrote:
to see what's going on on
oops, it seems there are other 'meaningless' item, which actually
caused the problem
Thanks for helps
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 10, 6:52 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
-Original Message-
From: [EMAIL PROTECTED] [mailto:python-
[EMAIL PROTECTED] On Behalf Of Fredrik Lundh
Sent: Wednesday, January 09, 2008 2:39 PM
To: [EMAIL PROTECTED]
Subject: Re: problem of converting a list to dict
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[1:-1]:
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 tried this
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 tried this
-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, Reedick, Andrew [EMAIL PROTECTED] wrote:
On Wed, 9 Jan 2008 14:34:26 -0600 Reedick, Andrew [EMAIL PROTECTED] wrote:
-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
On Jan 10, 7:34 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
-Original Message-
From: [EMAIL PROTECTED] [mailto:python-
[EMAIL PROTECTED] On Behalf Of John Machin
Sent: Wednesday, January 09, 2008 3:02 PM
To: [EMAIL PROTECTED]
Subject: Re: problem of converting a list to dict
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
17 matches
Mail list logo