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

Frederic Rentsch anthra.norell at bluewin.ch
Wed Aug 18 10:03:58 EDT 2010


On Mon, 2010-08-16 at 23:17 +0000, 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 loop. 
> 
> What do you think the list comprehension does, if not cycle through a 
> loop?
> 
> 
> -- 
> Steven

What I think is that list comprehensions cycle through a loop a lot
faster than a coded loop (for n in ...:). As at the time of my post only
coded loops had been proposed and the OP was concerned about speed, I
thought I'd propose a list comprehension. I guess my explanation was
poorly phrased. Thanks for the reminder.

Frederic





More information about the Python-list mailing list