Compressed notation

Write code · Medium · §3.3 Working with strings

Complete the function solution, which returns a shortened form of the string s. Each run of the same character repeated in a row is written as the character followed by the number of times it repeats.

A character that does not repeat in a row is written without a count. For example, "aaabccdddd" becomes "a3bc2d4".

Function

solution(s)

Constraints

Examples

sresult
'aaabccdddd''a3bc2d4'
'abc''abc'

Starter code

def solution(s):
    answer = ""
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.