Re: [BangPypers] List Problem..

2010-07-24 Thread Anand Balachandran Pillai
On Sat, Jul 24, 2010 at 10:09 AM, anuj abhishek wrote: > I am not very sure about what you are asking for.. > But, if it's just a dictionary that you want from the given list then I > beleive > the folloeing will work.. > >>> x=[['cat',30],['cat',40],['cat',10],['dog',5],['dog',7],['dog',1]] > >>>

Re: [BangPypers] List Problem..

2010-07-23 Thread anuj abhishek
gt; [...] > > 31st is fine by me. Anyone else? > > -- > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- Message: 4 Date: Thu, 22 Jul 2010 19:00:43 +05

Re: [BangPypers] list problem

2010-07-23 Thread steve
On 07/23/2010 10:34 AM, Navin Kabra wrote: On Thu, Jul 22, 2010 at 7:31 PM, Shashwat Anand wrote: Are you sure that'll work ? Is creating a dict from a sequence guaranteed to be executed serially withing the sequence ? It is nowhere mentioned in Docs IIRC but I have never seen any counter

Re: [BangPypers] list problem

2010-07-23 Thread Baishampayan Ghose
> For worst case and dataset in problem your script beats all. > For simple but large data it's Anand's solution just slightly ahead. > > Wow. Thanks for the info, Shekhar. I am happy :) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com ___ BangP

Re: [BangPypers] list problem

2010-07-23 Thread Shekhar Tiwatne
On Friday 23 July 2010 09:11 AM, Baishampayan Ghose wrote: Out of curiosity I tried benchmarking few of these solutions alongwith the one I wrote using itertools.groupby. My benchmarking did include large data sets and worst case. Results are the shortest solution (by Anand) was way faster than o

Re: [BangPypers] list problem

2010-07-22 Thread Navin Kabra
On Thu, Jul 22, 2010 at 7:31 PM, Shashwat Anand wrote: >> Are you sure that'll work ? Is creating a dict from a sequence guaranteed >> to be executed serially withing the sequence ? > > It is nowhere mentioned in Docs IIRC but I have never seen any counter > example. Actually it is guaranteed. >F

Re: [BangPypers] list problem

2010-07-22 Thread Baishampayan Ghose
> Out of curiosity I tried benchmarking few of these solutions alongwith the > one I wrote using itertools.groupby. > My benchmarking did include large data sets and worst case. > Results are the shortest solution (by Anand) was way faster than others. > After that it was Steve's and mine and Navin

Re: [BangPypers] list problem

2010-07-22 Thread Shashwat Anand
On Thu, Jul 22, 2010 at 10:37 PM, Shekhar Tiwatne wrote: > On Thursday 22 July 2010 09:36 PM, Anand Balachandran Pillai wrote: > >> On Thu, Jul 22, 2010 at 7:00 PM, steve wrote: >> >> >> >>> Hi, >>> >>> >>> On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote: >>> >>> >>> On Thu, Jul 22,

Re: [BangPypers] list problem

2010-07-22 Thread Shekhar Tiwatne
On Thursday 22 July 2010 09:36 PM, Anand Balachandran Pillai wrote: On Thu, Jul 22, 2010 at 7:00 PM, steve wrote: Hi, On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote: On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: Suppose you have the following list: >>>

Re: [BangPypers] list problem

2010-07-22 Thread Anand Balachandran Pillai
On Thu, Jul 22, 2010 at 7:00 PM, steve wrote: > Hi, > > > On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote: > >> On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: >> >> Suppose you have the following list: >>> >>> >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] >>

Re: [BangPypers] list problem

2010-07-22 Thread Shashwat Anand
On Thu, Jul 22, 2010 at 7:00 PM, steve wrote: > Hi, > > > On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote: > >> On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: >> >> Suppose you have the following list: >>> >>> >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] >>

Re: [BangPypers] list problem

2010-07-22 Thread Shashwat Anand
On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: > Suppose you have the following list: > > >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] > > My problem is that i wish to obtain the following two dictionaries: > xdictstart = {'cat':10, 'dog':1} > xdictend = {'cat':30, 'dog

Re: [BangPypers] list problem

2010-07-22 Thread Vikram
many thanks for this to naveen and others who responded. On Thu, 22 Jul 2010 15:54:14 +0530 wrote >I suggest that in such cases, avoid the temptation to do something clever. If it was difficult for you to write the code, it will be even more difficult to read and understand it. Unless there

Re: [BangPypers] list problem

2010-07-22 Thread steve
Hi, On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote: On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: Suppose you have the following list: >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] My problem is that i wish to obtain the following two dictionaries: x

Re: [BangPypers] list problem

2010-07-22 Thread Anand Balachandran Pillai
On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote: > Suppose you have the following list: > > >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] > > My problem is that i wish to obtain the following two dictionaries: > xdictstart = {'cat':10, 'dog':1} > xdictend = {'cat':30, 'dog

Re: [BangPypers] list problem

2010-07-22 Thread Baishampayan Ghose
> Suppose you have the following list: > x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] > > My problem is that i wish to obtain the following two dictionaries: > xdictstart = {'cat':10, 'dog':1} > xdictend = {'cat':30, 'dog':5} > > Any nice way to do the above? Thanks. Do

Re: [BangPypers] list problem

2010-07-22 Thread Emil Chacko
>>> for subLi in x: ... if(xdictstart.has_key(subLi[0])): ... if(xdictstart[subLi[0]]>subLi[1]): ...xdictstart[subLi[0]]=subLi[1] ... else: ... xdictstart[subLi[0]]=subLi[1] The opposite can be done to obtain the xdictend.This is one way.There might be some easier way's but i'm not aware

Re: [BangPypers] list problem

2010-07-22 Thread steve
On 07/22/2010 03:21 PM, Vikram wrote: Suppose you have the following list: x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] My problem is that i wish to obtain the following two dictionaries: xdictstart = {'cat':10, 'dog':1} xdictend = {'cat':30, 'dog':5} I don't get it,

Re: [BangPypers] list problem

2010-07-22 Thread Kenneth Gonsalves
On Thursday, July 22, 2010 03:21:38 pm Vikram wrote: > Suppose you have the following list: > >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] > > My problem is that i wish to obtain the following two dictionaries: > xdictstart = {'cat':10, 'dog':1} > xdictend = {'cat':30, '

Re: [BangPypers] list problem

2010-07-22 Thread Navin Kabra
I suggest that in such cases, avoid the temptation to do something clever. If it was difficult for you to write the code, it will be even more difficult to read and understand it. Unless there is a very good reason, write the simplest, most braindead code. xdictstart={} xdictend={} for item in sor

[BangPypers] list problem

2010-07-22 Thread Vikram
Suppose you have the following list: >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] My problem is that i wish to obtain the following two dictionaries: xdictstart = {'cat':10, 'dog':1} xdictend = {'cat':30, 'dog':5} Any nice way to do the above? Thanks. --- Those in