How to remove duplicates of a single character in string python?

Question:

I have a string like this:
$$\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}{{e^{(x+y)}}^2}dxdy$$

but what i want is:
$$int_{-infty}^{infty}int_{-infty}^{infty}{{e^{(x+y)}}^2}dxdy$$

Is there a way to do that?

Asked By: Pierluigi

||

Answers:

First of all, if this is a string literal, then it will properly escape the slash, and you will get the result you want:

print("$$\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}{{e^{(x+y)}}^2}dxdy$$")

Otherwise, you could just replace the characters with one of it:

string = "$$\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}{{e^{(x+y)}}^2}dxdy$$"

string = string.replace(r'\', '\')
Answered By: Xiddoc
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.