Suppose I have a string value str=xxx
. Now I want to replace it via multi-index, such as {(1, 3):'rep1', (4, 7):'rep2', (8, 9):'rep3'}
, without disturbing the index order. How can I do it?
Pseudo-code (in Python 2.7):
str = 'abcdefghij'
replacement = {(1, 3):'123', (4, 7):'+', (8, 9):'&'} # right index isn't include
# after some replacements:
str = some_replace(str, replacement)
# i want to get this:
print str
# 'a123d+h&j'