21Run-Length Encoding

    Mediumstringsloops

    Run-length encoding replaces each run of the same character with the character followed by how many times it repeats.

    Write encode(text) so that encode("aaabcc") returns "a3b1c2".

    Examples

    Example 1
    >>> encode('aaabcc')
    'a3b1c2'
    Example 2
    >>> encode('abc')
    'a1b1c1'

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write encode in the editor, then run the examples. Use print() freely: its output is shown for each test.