import re
# '.{1,2}' 解释:1最小可分块,2平均分块
s = re.findall('.{1,2}', str(a))
print(s)
# ['ab', 'ab', 'ab', 'ab', 'ab', 'a']
from math import ceil # 小数向上取整
def chunk(lst, size):
"""
lst:支持字符串,列表
"""
return list(
map(lambda x: lst[x * size:x * size + size],
list(range(0, ceil(len(lst) / size)))))
a = "abababababa"
print(chunk(a, 2))
# ['ab', 'ab', 'ab', 'ab', 'ab', 'a']