problem of converting a list to dict

2008-01-09 Thread Louis . Soninhu
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={}

Re: problem of converting a list to dict

2008-01-09 Thread Marc 'BlackJack' Rintsch
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:

Re: problem of converting a list to dict

2008-01-09 Thread Fredrik Lundh
[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

Re: problem of converting a list to dict

2008-01-09 Thread Louis . Soninhu
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

Re: problem of converting a list to dict

2008-01-09 Thread Louis . Soninhu
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:

Re: problem of converting a list to dict

2008-01-09 Thread Fredrik Lundh
[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

Re: problem of converting a list to dict

2008-01-09 Thread John Machin
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:

RE: problem of converting a list to dict

2008-01-09 Thread Reedick, Andrew
-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

Re: problem of converting a list to dict

2008-01-09 Thread Louis . Soninhu
oops, it seems there are other 'meaningless' item, which actually caused the problem Thanks for helps -- http://mail.python.org/mailman/listinfo/python-list

Re: problem of converting a list to dict

2008-01-09 Thread John Machin
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

Re: problem of converting a list to dict

2008-01-09 Thread Tim Chase
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]:

Re: problem of converting a list to dict

2008-01-09 Thread John Machin
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

Re: problem of converting a list to dict

2008-01-09 Thread bsneddon
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

RE: problem of converting a list to dict

2008-01-09 Thread Reedick, Andrew
-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:

Re: problem of converting a list to dict

2008-01-09 Thread Mike Meyer
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

Re: problem of converting a list to dict

2008-01-09 Thread John Machin
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

Re: problem of converting a list to dict

2008-01-09 Thread Matt Nordhoff
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