On Wed, Apr 9, 2008 at 4:15 PM, Dinesh B Vadhia
<[EMAIL PROTECTED]> wrote:
> Sorry, let's start again.

This version really isn't any more helpful than the first one.  I know
you corrected the sample code, but you haven't addressed any of the
fundamental questions that Kent or I asked.

> I want to replace the for loop with another structure to improve performance
> (as the data list will contain >10,000 string items].  At each iteration of
> the for loop the result is printed (in fact, the result is sent from the
> server to a browser one result line at a time)

Are you looking for a different data structure to hold your list of
strings, or are you looking for a replacement for the for loop?  How
long does it take to generate your list?  How long does each iteration
of your for loop take?  What are acceptable times for each of these?
You need to know these things before you can seriously optimize
anything.

If building up the list takes a long time and you only use it once,
consider using a generator instead of building the whole list and then
processing it.  This spreads out the time to create the list and
operates on each piece of data as soon as it's available.

I don't think you're going to find a replacement for a for loop that
is inherently faster.  You keep talking about list comprehensions, but
I don't see how a list comprehension is even appropriate for the
problem you're describing.

> The for loop will be called continuously and this is another reason to look
> for a potentially better structure preferably a built-in.

Again, it would be helpful to discuss actual bits of code, so we can
see if there are places you can gain some performance.  It's hard to
optimize psuedocode, because there are sometimes very minor changes
you can make which affect performance quite a bit. For instance,
attribute lookup in python is relatively slow.  If you can hoist any
attribute lookups out of your loop, you will get some performance
increases.

Also, you should mention what version of python you're using and what
platform it's running on.

-- 
Jerry
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to