I'm having an issue with finding the best way to restart a character counter that replaces repeating characters with variables. My code looks like so.
file = rf.read() ret = '' for k, v in groupby(s): x = '0' chunk = list(v) cnt = len(chunk) if k == x and cnt == 2: el = 'B' elif k == x and cnt == 3: el = 'C' else: el = ''.join(chunk) ret += el
So if the number is greater than 3, I wan't the counter to put C for those repeating characters then start counter over again. The numbers can get rather large so using a remainder function is out of the questions. Kinda looking for code that will just replace it with the highest number I have and restart counter like so.
Elif k == x and cnt >= 3: "print C for those 3 characters then start count over"
So if x is repeating 12 times the output would look like CCCC, Not sure if finding the repeating characters and dividing would be the best way to do it, because if it lands on a uneven number.