To determine how many consecutive same characters are there in a string, you can iterate over the string and keep track of the previous character. If the current character is the same as the previous one, increase a counter. If the current character is different from the previous one, reset the counter. Here's an example code:
main.py259 chars16 lines
This will output:
main.py12 chars4 lines
In this example, we assume that the string only contains letters. If your string might contain non-letter characters, you may want to add a check to only count consecutive same alphanumeric characters.
gistlibby LogSnag