Encode character runs
Return (character, count) tuples for consecutive runs in a string. Adjacent equal characters form one run; separate runs stay separate.
last_run = ('a', 2)
next_char = 'a'
print((next_char, last_run[1]+1))Reason about the state
Compare each character with the final run. Extend it or append a new run; each character is processed once. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return (character, count) tuples for consecutive runs in a string. Adjacent equal characters form one run; separate runs stay separate.
The explanation opens here once every check passes.