Any suggestions?

Aahz Maruch aahz at panix.com
Fri Sep 22 18:48:25 EDT 2000


In article <8qgev7$oir$1 at nnrp1.deja.com>,  <rick_richardson at my-deja.com> wrote:
>Aahz:
>>
>> That seems a little odd.  Are these non-trivial projects?  Have you done
>> any work to optimize the Python code?
>
>I didn't know I could.

Of course you can.  Here's a simple example:

  str = ''
  for word in words:
    str = str + ' ' + word

That code can be easily optimized to

  str = string.join(words)

Every language has its efficient coding tricks; the neat thing about
Python is that once you've gotten a decent handle on its tricks, you can
concentrate on algorithmic improvements -- even if your C code is a
hundred times faster than the Python code, you'll be unhappy as soon as
you hit non-trivial inputs if your C code is O(N^2) and your Python code
is O(NlogN).
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Member of the Groucho Marx Fan Club  --Aahz



More information about the Python-list mailing list