https en wikipedia orgwikirunlengthencoding performs run length encoding runlengthencodeaaaabbbccdaa a 4 b 3 c 2 d 1 a 2 runlengthencodea a 1 runlengthencodeaa a 2 runlengthencodeaaaddddddfffcccaavvvv a 3 d 6 f 3 c 3 a 2 v 4 performs run length decoding runlengthdecode a 4 b 3 c 2 d 1 a 2 aaaabbbccdaa runlengthdecode a 1 a runlengthdecode a 2 aa runlengthdecode a 3 d 6 f 3 c 3 a 2 v 4 aaaddddddfffcccaavvvv https en wikipedia org wiki run length_encoding performs run length encoding run_length_encode aaaabbbccdaa a 4 b 3 c 2 d 1 a 2 run_length_encode a a 1 run_length_encode aa a 2 run_length_encode aaaddddddfffcccaavvvv a 3 d 6 f 3 c 3 a 2 v 4 performs run length decoding run_length_decode a 4 b 3 c 2 d 1 a 2 aaaabbbccdaa run_length_decode a 1 a run_length_decode a 2 aa run_length_decode a 3 d 6 f 3 c 3 a 2 v 4 aaaddddddfffcccaavvvv
def run_length_encode(text: str) -> list:
    
    encoded = []
    count = 1

    for i in range(len(text)):
        if i + 1 < len(text) and text[i] == text[i + 1]:
            count += 1
        else:
            encoded.append((text[i], count))
            count = 1

    return encoded


def run_length_decode(encoded: list) -> str:
    
    return "".join(char * length for char, length in encoded)


if __name__ == "__main__":
    from doctest import testmod

    testmod(name="run_length_encode", verbose=True)
    testmod(name="run_length_decode", verbose=True)