I've written a program which can compress a sequence of characters.

```
def compress(string):
    output = ""
    counter = 1
    firstLoop = True

    for element in range(0, len(string)):
        # if statement checking if current character was last character
        if string[element] == string[element - 1]:
            # if it was, then the character has been written more than one
            # time in a row, so increase counter
            counter = counter + 1
        else:
            # when we detect a new character reset the counter
            # and also record the character and how many times it was repeated
            if not firstLoop:
                output = output + string[element - 1] + str(counter)
        counter = 1

        firstLoop = False
    return output

data = "aaaabbbchhtttttttf"
print(data)

compressedData = compress(data)
print(compressedData)

```

The program outputs:

```
aaaabbbchhtttttttf
a4b3c1h2t7

```

So, it finds that there's '4' entries of 'a' so it writes 'a4', then 'b3' for three entries of b.

The issue is that it forgets about the 'f1' at the end of the string. I know this is because of the line:

```
output = output + string[element - 1] + str(counter)

```

Since string[element-1] refers to the position in the string before the current element, thus, it will never reach the final position which is where 'f' is. The program doesn't work without the '-1' since it doesn't write the correct letter.

How can I get around this problem and make it able to include f?

The correct output should be a4b3c1h2t7f1.

Thanks :)

Edit: I forgot to mention that the program works if I include an additional character after the 'f', such as just a blank space. But that's of course because the final character in my string is just a space rather than a letter.