> > If the OP is constrained to standard libraries, then it may be a > question of defining what should be done more clearly. The extraneous > spaces can be removed by tokenizing the string and rejoining the > tokens. Replacing portions of a string with equivalents is standard > stuff. It might be preferable to create a function that will accept > lists of from and to strings and translate the entire string by > successively applying the replacements. From what I've seen so far, > that would be all the OP needs for this task. It might take a half- > dozen lines of code, plus the from/to table definition.
The OP had <br>-tags in his text. Which is _more_ than a half dozen lines of code to clean up. Because your simple replacement-approach won't help here: <br>foo <br> bar </br> Which is perfectly legal HTML, but nasty to parse. Diez -- http://mail.python.org/mailman/listinfo/python-list