Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Terry Reedy
On 9/28/2011 5:28 AM, Xah Lee wrote: curious question. suppose you have 300 different strings and they need all be replaced to say "aaa". is it faster to replace each one sequentially (i.e. replace first string to aaa, then do the 2nd, 3rd,...) , or is it faster to use a regex with “or” them al

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread John Bokma
Willem writes: > Eli the Bearded wrote: > ) In comp.lang.perl.misc, Willem wrote: > )> In Perl, it would be applicable. You see, in Perl, you can call a function > )> in the replacement of the regex substitution, which can then look up the > )> html entity and return the wanted unicode literal

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Willem
Eli the Bearded wrote: ) In comp.lang.perl.misc, Willem wrote: )> In Perl, it would be applicable. You see, in Perl, you can call a function )> in the replacement of the regex substitution, which can then look up the )> html entity and return the wanted unicode literal. ) ) A function? I'd use a

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Eli the Bearded
In comp.lang.perl.misc, Willem wrote: > In Perl, it would be applicable. You see, in Perl, you can call a function > in the replacement of the regex substitution, which can then look up the > html entity and return the wanted unicode literal. A function? I'd use a hash. > I think you can do th

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Ian Kelly
On Wed, Sep 28, 2011 at 3:28 AM, Xah Lee wrote: > curious question. > > suppose you have 300 different strings and they need all be replaced > to say "aaa". > > is it faster to replace each one sequentially (i.e. replace first > string to aaa, then do the 2nd, 3rd,...) > , or is it faster to use a

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread MRAB
On 28/09/2011 18:00, Willem wrote: Xah Lee wrote: ) the question originally came from when i was coding elisp of a ) function that changes html entities to unicode char literal. The ) problem is slightly complicated, involving a few questions about speed ) in emacs. e.g. string vs buffer, and muc

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Willem
Xah Lee wrote: ) the question originally came from when i was coding elisp of a ) function that changes html entities to unicode char literal. The ) problem is slightly complicated, involving a few questions about speed ) in emacs. e.g. string vs buffer, and much more... i spent several ) hours on

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 11:22 PM, Neil Cerutti wrote: > I'd like to know what "string replacement" is supposed to mean in > the context of Python. > Substring replacement, such as: >>> "Hello, world!".replace(", "," -- ") 'Hello -- world!' The str method doesn't accept a list, though, so it won'

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Roy Smith
In article <9egld1f38...@mid.individual.net>, Neil Cerutti wrote: > On 2011-09-28, Chris Angelico wrote: > > On Wed, Sep 28, 2011 at 10:28 PM, Xah Lee wrote: > >> each string needs to be changed to a unique string, not all to > >> the same string. > > > > And you'll find that this is, by and l

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Neil Cerutti
On 2011-09-28, Chris Angelico wrote: > On Wed, Sep 28, 2011 at 10:28 PM, Xah Lee wrote: >> each string needs to be changed to a unique string, not all to >> the same string. > > And you'll find that this is, by and large, the most normal > situation. Folding many strings down to one string is a l

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 11:14 PM, Xah Lee wrote: > (while (< ii (length pairs)) >      (setq mystr (replace-regexp-in-string >                   (elt tempMapPoints ii) >                   (elt (elt pairs ii) 1) >                   mystr t t)) >      (setq ii (1+ ii)) >      ) from __future__ impo

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Xah Lee
here's more detail about the origin of this problem. Relevant to emacs lisp only. -- in the definition of “replace-regexp-in-string”, there's this comment: ;; To avoid excessive consing from multiple matches in long strings, ;; don't just call `replace-match' cont

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 10:28 PM, Xah Lee wrote: > each string needs to be changed to a unique > string, not all to the same string. And you'll find that this is, by and large, the most normal situation. Folding many strings down to one string is a lot less common. So, let's have some real-world

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Xah Lee
On Sep 28, 3:57 am, mer...@stonehenge.com (Randal L. Schwartz) wrote: > > "Xah" == Xah Lee writes: > > Xah> curious question. > Xah> suppose you have 300 different strings and they need all be replaced > Xah> to say "aaa". > > And then suppose this isn't the *real* question, but one entirely o

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Randal L. Schwartz
> "Xah" == Xah Lee writes: Xah> curious question. Xah> suppose you have 300 different strings and they need all be replaced Xah> to say "aaa". And then suppose this isn't the *real* question, but one entirely of Fiction by Xah Lee. How helpful do you want to be? -- Randal L. Schwartz - St

Re: question about speed of sequential string replacement vs regex or

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 7:28 PM, Xah Lee wrote: > suppose you have 300 different strings and they need all be replaced > to say "aaa". > > is it faster to replace each one sequentially Before you ask "is it faster", you need to first be sure it's correct. I would recommend doing all the replaces

question about speed of sequential string replacement vs regex or

2011-09-28 Thread Xah Lee
curious question. suppose you have 300 different strings and they need all be replaced to say "aaa". is it faster to replace each one sequentially (i.e. replace first string to aaa, then do the 2nd, 3rd,...) , or is it faster to use a regex with “or” them all and do replace one shot? (i.e. "1stst