Here is what I have:
stem_text = "x^3+21x^2+1x+6"
And I would like to change it to:
stem_text = "x^3+21x^2+x+6"
Here's what my code looks like:
indices = [m.start() for m in re.finditer("1x", stem_text)]
for i in indices:
if stem_text[i-1] not in ["0","1","2","3","4","5","6","7","8","9"]:
stem_text = stem_text.replace(stem_text[i:i+2],"x")`
But, it is replacing both occurrences of "1x" still.
I have used these two posts to get me to a point where I think what I have should be working, but it is not: