+= overloading?

John Machin machin_john_888 at hotmail.com
Tue Jun 19 01:02:43 CEST 2001


"Neil Macneale" <mac4-devnull at theory.org> wrote in message news:<3b2e3554$0$331$8eec23a at newsreader.tycho.net>...
> I am using a list as the data holding element, then appending to it in
> the __iadd__ function. Then I use ''.join(list) to make a string
> when the __str__ function is called.  I am doing this to minimize the
> number of string objects created,  and figure that append runs in
> constant time.  Is join optomized though?  It would defeat the purpose if
> join worked by creating a new string to join the first two, then added
> the third, etc.  I am assumming that join is implemented in C, and runs
> in 0(n) time, where n is the number of total characters.  Am I assuming
> incorrectly?  I looked at string.py's join function, but that just called
> another join method, and I don't know where that one is implemented.

Either (1) don't assume; (a) download the source [doesn't take long]
and look in stringobject.c and/or (b) search this newsgroup --
behaviour of append() and join() just might have been discussed before
or (2) you might reason that join() has been around for a long time
and any far-less-than-optimal algorithm implemented in an extremely
rare moment of whatever by the gurus would have been pounced upon
triumphantly and fixed by one of the many eager kibitzers.



More information about the Python-list mailing list