#
from itertools import groupby
def compress(data):
return ((name, len(list(group))) for name, group in groupby(data))
def decompress(data):
return (name * size for name, size in data)
c = compress('get uuuuuuuuuuuuuuuuuuuuuuuup')
print(''.join(decompress(c)))
grouby函数类似Unix命令uniq,对相邻的重复元素进行分组。
groupby(iterable[, keyfunc]) -> create an iterator which returns (key, sub-iterator) grouped by each value of key(value).