Hey guys I'm trying to get an output of a4b2c1a2d3 with an input of aaaabbcaaddd. I think the problem with my code below is the way I implement the counter for previous. Is there an issue with index > 0:?
string1 = "aaaabbcaaddd"
previous = ""
finalstr = ""
finalint = 1
for index, val in enumerate(string1):
if index > 0:
previous = string1[index - 1]
if previous == val:
finalint += 1
else:
finalstr += previous + str(finalint)
finalint = 1
print(finalstr)
#outputs "a4b2c1a2"
finalstr += previous + str(finalint).