0

enter image description here

Does anyone know how to decompress the RLE algorithm but the input must start with a letter for example "A2B5". The input from my program starts with a number, for example "2B5B".

TitikKoma
  • 1
  • 1

1 Answers1

0

Here is an implementation of the algorithm assuming only single letters are to be replicated and multiple digits are to be supported.

compressed = "A10B5"

def is_digit(s):
    try:
        int(s)
        return True
    except:
        return False

def decompress(c):
    result = ""
    ch = ''
    count = 0
    for i in c:
        if is_digit(i):
            count = count * 10 + int(i)
        else:
            result += ch * count
            count = 0
            ch = i
    result += ch * count
    return result

print(decompress(compressed))
mmmm
  • 16
  • 4