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]]
> >>>
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
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
> 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
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
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
> 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
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,
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:
>>>
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]]
>>
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]]
>>
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
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
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
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
> 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
>>> 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
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,
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, '
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
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
21 matches
Mail list logo