Say I have a string that looks like this:
str = \"The &yquick &cbrown &bfox &Yjumps over the &ulazy dog\"
You\'ll notic
The problem with doing this mass replace in Python is immutability of the strings: every time you will replace one item in the string then entire new string will be reallocated again and again from the heap.
So if you want the fastest solution you either need to use mutable container (e.g. list), or write this machinery in the plain C (or better in Pyrex or Cython). In any case I'd suggest to write simple parser based on simple finite-state machine, and feed symbols of your string one by one.
Suggested solutions based on regexps working in similar way, because regexp working using fsm behind the scene.