Re: which is better, string concatentation or substitution?

2006-05-12 Thread bruno at modulix
Ted wrote: > Thank you Roy. > > It seems if you lurk here long enough you eventually get all you > questions answered without even asking! > ;-) > +1 QOTW please avoid top-posting, and please avoid posting back a long message just to add three lines. -- bruno desthuilliers python -c "print '

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Casey Hawthorne <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] (Roy Smith) wrote: > > >O(n^0), which is almost always written as O(1). This is a "constant > >time" algorithm, one which takes the same amount of steps to execute > >no matter how big the input is.

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Casey Hawthorne
[EMAIL PROTECTED] (Roy Smith) wrote: >O(n^0), which is almost always written as O(1). This is a "constant >time" algorithm, one which takes the same amount of steps to execute >no matter how big the input is. For example, in python, you can >write, "x = 'foo'". That assignment statement takes t

Re: which is better, string concatentation or substitution?

2006-05-08 Thread John Salerno
Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > John Salerno <[EMAIL PROTECTED]> wrote: >> Roy Smith wrote: >> >>> OK, here's a quick tutorial to "big-oh" notation. >> Wow, that was fantastic (and interesting)! Did you just write that? That >> should be saved somewhere! Mind if I post it on

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Roy Smith
In article <[EMAIL PROTECTED]>, John Salerno <[EMAIL PROTECTED]> wrote: >Roy Smith wrote: > >> OK, here's a quick tutorial to "big-oh" notation. > >Wow, that was fantastic (and interesting)! Did you just write that? That >should be saved somewhere! Mind if I post it on my website? (don't >worry

Re: which is better, string concatentation or substitution?

2006-05-08 Thread John Salerno
Roy Smith wrote: > OK, here's a quick tutorial to "big-oh" notation. Wow, that was fantastic (and interesting)! Did you just write that? That should be saved somewhere! Mind if I post it on my website? (don't worry, no one goes there anyway) :) -- http://mail.python.org/mailman/listinfo/pytho

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Ted
Thank you Roy. It seems if you lurk here long enough you eventually get all you questions answered without even asking! ;-) Roy Smith wrote: > John Salerno <[EMAIL PROTECTED]> wrote: > >Roy Smith wrote: > > > >> One may be marginally faster, but they both require copying the source > >> string,

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Roy Smith
John Salerno <[EMAIL PROTECTED]> wrote: >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. OK, here's a quick tutorial to "big-oh" notation. It's a way of measuring a

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Peter Otten
John Salerno wrote: > Duncan Booth wrote: > >> If you build a >> list of lines to join then you don't have to repeat '\n' on the end of >> each component line. > > How would that work? Wouldn't the last line in the list still need the > newlines? >>> chunks = ["alpha", "beta", "gamma"] >>> "\n"

Re: which is better, string concatentation or substitution?

2006-05-08 Thread John Salerno
Duncan Booth wrote: > If you build a > list of lines to join then you don't have to repeat '\n' on the end of each > component line. How would that work? Wouldn't the last line in the list still need the newlines? -- http://mail.python.org/mailman/listinfo/python-list

Re: which is better, string concatentation or substitution?

2006-05-08 Thread John Salerno
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

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Roy Smith
In article <[EMAIL PROTECTED]>, John Salerno <[EMAIL PROTECTED]> wrote: > My initial feeling is that concatenation might take longer than > substitution, but that it is also easier to read: > > > def p(self, paragraph): > self.source += '' + paragraph + '\n\n' > > vs. > > def p(self, pa

Re: which is better, string concatentation or substitution?

2006-05-08 Thread Duncan Booth
Leif K-Brooks wrote: > fuzzylollipop wrote: >> niether .join() is the fastest > > Please quote what you're replying to. > > No, it's the slowest: > > [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" > 100 loops, best of 3: 0.607 usec per loop > [EMAIL PROTECTED]:~$ python -m time

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
fuzzylollipop wrote: > niether .join() is the fastest Please quote what you're replying to. No, it's the slowest: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.607 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 100 loops

Re: which is better, string concatentation or substitution?

2006-05-07 Thread fuzzylollipop
niether .join() is the fastest -- http://mail.python.org/mailman/listinfo/python-list

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
John Salerno wrote: > My initial feeling is that concatenation might take longer than > substitution Doesn't look that way: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.6 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 1

which is better, string concatentation or substitution?

2006-05-07 Thread John Salerno
My initial feeling is that concatenation might take longer than substitution, but that it is also easier to read: def p(self, paragraph): self.source += '' + paragraph + '\n\n' vs. def p(self, paragraph): self.source += '%s\n\n' % paragraph Is there a preference between these two