Split string every nth character?

 

https://stackoverflow.com/questions/9475241/split-string-every-nth-character

 

>>> line = '1234567890'
>>> n = 2
>>> [line[i:i+n] for i in range(0, len(line), n)]
['12', '34', '56', '78', '90']

 

posted on 2017-09-28 17:10  蚂蚁flow  阅读(160)  评论(0编辑  收藏  举报

导航