把 aaabbcccd 这种形式的字符串压缩成 a3b2c3d1 这种形式。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
print(''.join({i+str(s.count(i)) for i in s}))
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
dic={} for i in s: if i in dic: dic[i]+=1 else: dic[i]=1 s1='' for i,j in dic.items(): s1+=i s1+=str(j) print(s1)
Python 一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程找出 1000 以内的所有完数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
num=[] for i in range(1001): lis = [] for j in range(1, i//2+1): if i % j == 0: lis.append(j) if sum(lis)==i: num.append(i) print(num)
本文来自博客园,作者:topass123,转载请注明原文链接:https://www.cnblogs.com/topass123/p/12589021.html