question 105 String Algorithms · medium
Decode run-length text
Run-length encoding writes each run as a character followed by its length: W4B3W12 means 4 W, 3 B, then 12 W. Decode an encoded text. The length can have several digits. The character itself is never a digit. If the text breaks the format (starts with a digit, or a character has no length after it), return None.
Function
decode(encoded)Returnsthe decoded text,
"" for an empty input, or None if the format is brokenFormatone or more pairs of a non-digit character and a whole number of at least one digit
Examples
calldecode('W4B3W12')returns'WWWWBBBWWWWWWWWWWWW'
calldecode('a1b1c1')returns'abc'
calldecode('')returns''