Speed of string += string

Alex Martelli aleax at aleax.it
Sun Apr 13 05:27:20 EDT 2003


Alan McIntyre wrote:

> I wasn't interested in the time to execute the entire 200k append
> operations; as Mr. Martelli pointed out earlier, it's O(n^2), but the +=
> append (considered by itself) appears to be O(n).

Right: each append is O(N), so (since building up a long string of
small pieces requires O(N) appends) the overall operation is O(N**2).


Alex





More information about the Python-list mailing list