今天逛貼吧,繼續(xù)看到那個帖子(http://tieba.baidu.com/f?z=951652539&ct=335544320&lm=0&sc=0&rn=30&tn=baiduPostBrowser&word=python&pn=30)有人留言。而且感覺方法很不錯,使用的是itertools中的一個工具。在這里向50樓學習了。
from itertools import zip_longest
def str_split(str, n):
"str_split('aabbcc', 2) --> ['aa', 'bb', 'cc']"
args = [iter(str)] * n
return [''.join(i) for i in zip_longest(*args, fillvalue='')]
閱讀全文 類別:Python 查看評論文章來源:
http://hi.baidu.com/mirguest/blog/item/49a57fb581ac40e731add12f.html