Re: Simple Problem but tough for me if i want it in linear time

2010-08-30 Thread Aahz
In article , Tim Chase wrote: >On 08/18/10 21:47, Steven D'Aprano wrote: >> >> Frankly, I think the OP doesn't really know what he wants, other than >> premature optimization. It's amazing how popular that is :) > >You see, the trick to prematurely optimizing is to have a good >algorithm for pre

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Tim Chase
On 08/18/10 21:47, Steven D'Aprano wrote: Frankly, I think the OP doesn't really know what he wants, other than premature optimization. It's amazing how popular that is :) You see, the trick to prematurely optimizing is to have a good algorithm for prematurely optimizing...the real question th

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Steven D'Aprano
On Wed, 18 Aug 2010 16:03:58 +0200, Frederic Rentsch wrote: > On Mon, 2010-08-16 at 23:17 +, Steven D'Aprano wrote: >> On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: >> >> > How about >> > >> [obj for obj in dataList if obj.number == 100] >> > >> > That should create a lis

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Frederic Rentsch
On Mon, 2010-08-16 at 23:17 +, Steven D'Aprano wrote: > On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: > > > How about > > > [obj for obj in dataList if obj.number == 100] > > > > That should create a list of all objects whose .number is 100. No need > > to cycle through a

Re: Simple Problem but tough for me if i want it in linear time

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: > How about > [obj for obj in dataList if obj.number == 100] > > That should create a list of all objects whose .number is 100. No need > to cycle through a loop. What do you think the list comprehension does, if not cycle throug

Re: Simple Problem but tough for me if i want it in linear time

2010-08-16 Thread Frederic Rentsch
On Sun, 2010-08-15 at 15:14 +0200, Peter Otten wrote: > ChrisChia wrote: > > > dataList = [a, b, c, ...] > > where a, b, c are objects of a Class X. > > In Class X, it contains self.name and self.number > > > > If i wish to test whether a number (let's say 100) appears in one of > > the object, a

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread Steven D'Aprano
On Sun, 15 Aug 2010 05:47:04 -0700, ChrisChia wrote: > dataList = [a, b, c, ...] > where a, b, c are objects of a Class X. In Class X, it contains > self.name and self.number > > If i wish to test whether a number (let's say 100) appears in one of the > object, and return that object, > is that o

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread MRAB
ChrisChia wrote: dataList = [a, b, c, ...] where a, b, c are objects of a Class X. In Class X, it contains self.name and self.number If i wish to test whether a number (let's say 100) appears in one of the object, and return that object, is that only fast way of solving this problem without iter

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread Peter Otten
ChrisChia wrote: > dataList = [a, b, c, ...] > where a, b, c are objects of a Class X. > In Class X, it contains self.name and self.number > > If i wish to test whether a number (let's say 100) appears in one of > the object, and return that object, > is that only fast way of solving this problem