简单程序的实现集合

1.判断一个非空字符串是否为多个重复的子字符串组成

2.把aaabbbff压缩成a3b3f2的形式

1.

a = 'asdasasdas'
for i in range(len(a)//2):
    if ((len(a)//(i+1))*a[:i+1]) == a:
        print('true')

2.

b = 'aaabbbbcccckkrrrrrrrrr'
num = 1
final = ''
for i in range(len(b)):
    if i == 0:
        final += b[0]
    else:
        if b[i] == b[i-1]:
            num += 1
        else:
            final += str(num) + b[i]
            num = 1
    if i == len(b)-1:
        final += str(num)
print(final)

 

posted @ 2019-07-10 10:51  车路历程  阅读(160)  评论(0编辑  收藏  举报