Re: replace string patern with different value

2005-05-09 Thread Bengt Richter
On Mon, 9 May 2005 15:48:14 +0200, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Bill Mill wrote: > > for rep in L: >> ... source = source.replace(token, rep, 1) > >here's another way to do it: > L = ["11", "22", "33"] S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"

Re: replace string patern with different value

2005-05-09 Thread [EMAIL PROTECTED]
Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: replace string patern with different value

2005-05-09 Thread Paul McGuire
Well, not to be left out, here is a pyparsing solution. But this looks suspiciously like some form of mail-merge or templating application. Google for 'python templating' for existing approaches to this problem. Interestingly, using an iterator of L sidesteps a number of other problems. My origi

Re: replace string patern with different value

2005-05-09 Thread Fredrik Lundh
Bill Mill wrote: for rep in L: > ... source = source.replace(token, rep, 1) here's another way to do it: >>> L = ["11", "22", "33"] >>> S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah" >>> L.reverse() >>> re.sub("xyzzy", lambda x: L.pop(), S) "11 text we've got 22 text 33 yeah

Re: replace string patern with different value

2005-05-09 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > I would like to replace string with different values, > For example : > source = 'kode1 bla bla kode1 bla kode1' > I have a list with each member will replace each of kode1. > L = [11,22,33] > So the new source will become: > newsource = '11 bla bla 22 bla 33' > > How c

Re: replace string patern with different value

2005-05-09 Thread Peter Otten
[EMAIL PROTECTED] wrote: > I would like to replace string with different values, > For example : > source = 'kode1 bla bla kode1 bla kode1' > I have a list with each member will replace each of kode1. > L = [11,22,33] > So the new source will become: > newsource = '11 bla bla 22 bla 33' Here's on

replace string patern with different value

2005-05-09 Thread Bill Mill
On 9 May 2005 06:23:41 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > I would like to replace string with different values, > For example : > source = 'kode1 bla bla kode1 bla kode1' > I have a list with each member will replace each of kode1. > L = [11,22,33] > So the new source

replace string patern with different value

2005-05-09 Thread [EMAIL PROTECTED]
Hello, I would like to replace string with different values, For example : source = 'kode1 bla bla kode1 bla kode1' I have a list with each member will replace each of kode1. L = [11,22,33] So the new source will become: newsource = '11 bla bla 22 bla 33' How can I do it ? I tried to find using s