小编don*_*hat的帖子

在 Python 中解码数字?

我有解码问题。首先将字符串'44444'编码为'54'. (5 次 4) 现在当我想解码'54'它的空时。(它确实对字母起作用)

该算法将字符串解码'4a3b2c''aaaabbbcc'。现在当我想解码'4a54'它只是给出'aaaa'但正确的解码是'aaaa44444'. 我怎样才能解码这个?

这是代码:

def decode_RLE(x):
    decode = ''
    count = ''
    for i in x:
        
        if i.isdigit():
            #append to count
            count += i
        else i: 
   
            decode += i * int(count)
            count = '' 
         
    return decode
Run Code Online (Sandbox Code Playgroud)

python algorithm python-3.x rle

0
推荐指数
1
解决办法
113
查看次数

标签 统计

algorithm ×1

python ×1

python-3.x ×1

rle ×1