首页 > 解决方案 > #python 2.7 如何运行长度解码(RLE 到字符串)

问题描述

我希望将 RLE 的一部分解码为非编码输出,例如:

01,01a01d57801d01a01,

进入

,ad888888888888888888888888888888888888888888888888888888888da,

我曾尝试使用此模块:

def decode(lst):
    return ''.join(c * n for n,c in lst)

但这给了我一个“太多的价值来解包”任何帮助将不胜感激。我不知道如何解决这个问题,即使不修复我的模块也可以,请任何帮助都是好的。

标签: pythonpython-2.7

解决方案


    import re

def decode(lst):
    return ''.join(c * int(n) for n,c in lst)

def openingthefile():
    x=1
    myfile=open('LogoRLE.txt','r')
    details =myfile.readline()
    while details is not "":
        mylist=re.findall(r'(\d\d)?(.)', details)
        print decode(mylist)
        details=myfile.readline()

    myfile.close()
    return details
contents=openingthefile()

mylist=re.findall(r'(\d\d)?(.)', contents)

推荐阅读