MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / run_length_decode

Function run_length_decode

data_compression/run_length_encoding.py:29–41  ·  view source on GitHub ↗

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),

(encoded: list)

Source from the content-addressed store, hash-verified

27
28
29def run_length_decode(encoded: list) -> str:
30 """
31 Performs Run Length Decoding
32 >>> run_length_decode([('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2)])
33 'AAAABBBCCDAA'
34 >>> run_length_decode([('A', 1)])
35 'A'
36 >>> run_length_decode([('A', 2)])
37 'AA'
38 >>> run_length_decode([('A', 3), ('D', 6), ('F', 3), ('C', 3), ('A', 2), ('V', 4)])
39 'AAADDDDDDFFFCCCAAVVVV'
40 """
41 return "".join(char * length for char, length in encoded)
42
43
44if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected