Re: String Replacement

2017-01-24 Thread Peter Pearson
On Mon, 23 Jan 2017 13:23:38 -0800 (PST), subhabangal...@gmail.com wrote: > I have a string like > > "Trump is $ the president of USA % Obama was $ the president > of USA % Putin is $ the premier of Russia%" > > Here, I want to extract the portions from $...%, which would be > > "the president of

Re: String Replacement

2017-01-23 Thread Chris Angelico
On Tue, Jan 24, 2017 at 8:23 AM, wrote: > I have a string like > > "Trump is $ the president of USA % Obama was $ the president of USA % Putin > is $ the premier of Russia%" > > Here, I want to extract the portions from $...%, which would be > > "the president of USA", > "the president of USA",

String Replacement

2017-01-23 Thread subhabangalore
I have a string like "Trump is $ the president of USA % Obama was $ the president of USA % Putin is $ the premier of Russia%" Here, I want to extract the portions from $...%, which would be "the president of USA", "the president of USA", "the premier of Russia" and would work some post extr

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(", "," -- ") 'H

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

2011-09-28 Thread Roy Smith
gt; > 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 use cases and then > > we can talk recommendations. > > I'd like to know what &q

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

2011-09-28 Thread Neil Cerutti
rings down to one string is a lot > less common. So, let's have some real-world use cases and then > we can talk recommendations. I'd like to know what "string replacement" is supposed to mean in the context of Python. -- Neil Cerutti "A politician is an arse

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

Re: percent string replacement with index

2008-06-25 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: > What I'm surprised is that this isn't supported: > > "%(1)s %(2)s" % ("zero", "one", "two") Thanks Terry and Matimus, actually I'm using 2.4 and considering upgrading now. ;) Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -

Re: percent string replacement with index

2008-06-24 Thread Matimus
On Jun 24, 12:26 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Ulrich Eckhardt wrote: > > What I'm surprised is that this isn't supported: > > >   "%(1)s %(2)s" % ("zero", "one", "two") > > > i.e. specifying the index in a sequence instead of the key into a map (maybe > > I would use [1] instead of

Re: percent string replacement with index

2008-06-24 Thread Terry Reedy
Ulrich Eckhardt wrote: What I'm surprised is that this isn't supported: "%(1)s %(2)s" % ("zero", "one", "two") i.e. specifying the index in a sequence instead of the key into a map (maybe I would use [1] instead of (1) though). Further, the key can't be a simple number it seems, which make

percent string replacement with index

2008-06-24 Thread Ulrich Eckhardt
Hi! I'm still mostly learning Python and there is one thing that puzzles me about string formatting. Typical string formatting has these syntaxes: "%s is %s" % ("GNU", "not Unix") "%(1)s %(2)s" % ("1":"one", "2":"two") What I'm surprised is that this isn't supported: "%(1)s %(2)s" % ("zer

Problems in string replacement

2007-05-09 Thread saif . shakeel
HI, Thanks for the reply.that seems to work,but i was doing this so as to attach it to a bigger code where it will be utilised before a parsing. #Input file and Output file path from user file_input = raw_input("Enter The ODX File Path:") (shortname,ext)=os.path.splitext(file_input) f