which is better, string concatentation or substitution?
John Salerno
johnjsal at NOSPAMgmail.com
Mon May 8 09:44:08 EDT 2006
Roy Smith wrote:
> One may be marginally faster, but they both require copying the source
> string, and are thus both O(n).
Sorry, I'm not familiar with the O(n) notation.
> If you're just doing one or a small fixed
> number of these, it really doesn't matter. Pick whichever one you think is
> easier to read.
Thanks guys. I have a handful of methods that each do this task once per
call, so I suppose this counts as not a lot, at least not at one time.
And it seems like a good point that the real problem could be constantly
concatenating with self.source, rather than the smaller pieces being put
together.
More information about the Python-list
mailing list