Speed of string += string

Alex Martelli aleax at aleax.it
Sun Apr 13 11:27:20 CEST 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).


More information about the Python-list mailing list