[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 can I do it ? I tried to find using string built in function > replace, but it will replace pattern with the same value. >
>>> source = 'kode1 bla bla kode1 bla kode1' >>> L = [11,22,33] >>> re.sub('kode1', (lambda m: str(L.pop(0))), source) '11 bla bla 22 bla 33' -- http://mail.python.org/mailman/listinfo/python-list