import sys
def super_reduced_string(s):
i=len(s)-1
while(i>0):
if(s[i]==s[i-1]):
s=s.replace(s[i],'')
s=s.replace(s[i-1],'')
i=len(s)-1
else:
i-=1
return (s)
For example, if I take a string "aaabccddd" so the value of i is 8 at the start. My if statement is true so the string becomes 'aaabccdd'.
After then I want to remove s[i-1] (s[7]) then your string should become "aaabccd"
Why does it raise an IndexError exception, saying that s[i-1] out of range?