get-a-cup-of-coffee slow

Courageous jkraska1 at san.rr.com
Thu Aug 9 19:57:40 EDT 2001


>Why is the first one so slow?

Because you're duplicating the entire string every time you add
a single character to it. A similar situation arises in Java; one should
use a StringBuffer object instead. In Python this can be accomplished
by appending chars to the end of a list and then stringifying it: no
StringBuffer needed.

C//




More information about the Python-list mailing list