淘先锋技术网

首页 1 2 3 4 5 6 7

压缩算法描述如下:

例如:a{ABBCCCDDDD}压缩后成为a{1A2B3C4D}

>>> from collections import Counter
>>> ''.join([ '%s%s'%i[::-1] for i in sorted(Counter(list("ABBCCCDDDD")).items())])
'1A2B3C4D'
>>> sorted(Counter(list("ABBCCCDDDD")).items())
[('A', 1), ('B', 2), ('C', 3), ('D', 4)]
>>> Counter(list("ABBCCCDDDD")).items()
dict_items([('A', 1), ('C', 3), ('B', 2), ('D', 4)])
>>> Counter(list("ABBCCCDDDD"))
Counter({'D': 4, 'C': 3, 'B': 2, 'A': 1})
>>> a = [1,2,3,4,5]
>>> a[::-1]
[5, 4, 3, 2, 1]
>>> 

 

转载于:https://www.cnblogs.com/fortwo/archive/2013/04/22/3036723.html