[Tutor] String concatenation too slow
W W
srilyk at gmail.com
Tue Jul 1 11:25:44 CEST 2008
> On Tuesday 01 July 2008 00:12, Shrutarshi Basu wrote:
<snip>
>>I've been
>> using string concatenation to read through the string, and then create
>> the new one based on a dictionary lookup. However it becomes very slow
>> once the string gets very long (several thousand characters). Part of
>> it is undoubtedly due to the fact that the algorithm is quadratic (i'm
>> trying to find a better way) but I was wondering if there might be a
>> faster alternative to string concatenation. Would appending to a list
>> of strings be faster? I'm going to be doing thousands of these
>> appends, so even a small boost would be helpful.
>> Thanks,
>> Basu
Basu,
You might find this study/links to be helpful! We just had a
discussion on this very concept, my guess is that you'll find the
results informative, and especially helpful.
At 04:28 AM 6/27/2008, Kent Johnson wrote:
On Fri, Jun 27, 2008 at 6:48 AM, Dick Moores <rdm at rcblue.com> wrote:
> Instead I've tried to find out if it's true what Alex Martelli
writes on p.
> 484 in the section, "Building up a string from pieces" in his _Python in a
> Nutshell_, 2nd ed., which covers Python 2.4x.
You might be interested in this, complete with a picture:
http://personalpages.tds.net/~kent37/blog/arch_m1_2004_08.html#e55
and this followup:
http://personalpages.tds.net/~kent37/blog/arch_m1_2004_08.html#e56
HTH,
Wayne
More information about the Tutor
mailing list