0
My question is the following, after receiving a string (can be numbers or letters), return this string with the addition of a SE character within this string there are repeated characters in SEQUENCE.
Using Python I know that there are modules like the counter that returns the number of times a character is repeated in a string, but I need to find out if this character is repeated N times in a row.
I thought about solving my problem by going through the user input, turning it into a list, and adding the character after the sequence, but I don’t know if it’s the most pythonic way to do it.
Example:
If the user provides as input "abaabaaaabab".
After the letter "a" repeats 4 times in a row,.
The output would be:
"abaabaaaacbab"
And if the letter "a" is repeated, say 8 times in a row, the output should be "aaaacaaaac" or just "aaaacaaaac"? In the first case I would probably solve the problem with simple substitution (I would replace "aaaa" with "aaaac" until there are no more "aaaa" sequences in the string). In the second case I would go through the String character by adding the characters "a" in a String or temporary list. Whenever you have a character that is not "a", check that the counter is greater than 4, in positive case concaten a "c". In both cases zero the counter.
– Anthony Accioly