[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 one way to do it with regular expressions:
>>> def make_sub(items):
... items = iter(items)
... def sub(m):
... return items.next()
... return sub
...
>>> re.compile("kode1").sub(make_sub(str(i) for i in [11, 22, 33]),
... "kode1 bla bla kode1 bla kode1")
'11 bla bla 22 bla 33'
Peter
--
http://mail.python.org/mailman/listinfo/python-list