python 基本字符串压缩
当前位置:以往代写 > Python教程 >python 基本字符串压缩
2019-06-14

python 基本字符串压缩

python 基本字符串压缩
python">class Zipper:
    def zipString(self, iniString):
        nlen = len(iniString)
        rest =[]
        i = 0
        endflag = 0
        while i < (nlen-1):
            for j in range(i+1, nlen):
                if iniString[i] == iniString[j]:
                    continue
                else:
                     rest.append((iniString[i], i, j))
                     endflag = j
                     break
            i = j

        rest.append((iniString[endflag], endflag, nlen))
        resStr = ""
        for item in rest:
            resStr += (item[0] + str(item[2]-item[1]))

        if len(resStr) >= nlen:
            return iniString
        else:
            return resStr
a = Zipper()
print a.zipString('aabcccccaaa')

b = Zipper()
print b.zipString('welcometonowcoderrrrr')

c = Zipper()
bstr= c.zipString('qwertyuioplkjhgfdsAzxcvbNM')
print type(bstr)

标签:python

    关键字:

在线提交作业