Why it is so dramatical?

Fearless Freep joconnor at cybermesa.com
Tue Sep 3 17:53:42 CEST 2002


"Bo M. Maryniuck" <b.maryniuk at forbis.lt> wrote in message news:<mailman.1031039705.9065.python-list at python.org>...
> On Monday 02 September 2002 05:47, Jay O'Connor wrote:
> > As a result Perl is much faster at some kinds of operations than
> > Python, and vice-versa.
> 
> Yeah, actually, but I just would like to find some optimal Python solutio
> n :)

Well..is it more efficient to treat it as a list of characters?

>>> x = " " * 10
>>> x = list (x)
>>> y = 'test str'
>>> x[0:len(y)] = list (y)
>>> z = 'another test string'
>>> x.extend(list(z))
>>> s =''.join (x)
>>> print s

'test str  another test string'

Treating a string as a list of character elements would allow you to
append to it and change the internals.   May be an improvement in
performance.

This assumes you are having a noticeable performance problem with
concatenating strings.  Beware of premature optimization.  Just
because an fairly simple operation in one language is slower than the
equivalent in another language doesn't mean that the program as a
whole will be slower enough to matter

Take care,
Jay



More information about the Python-list mailing list