作者emind ( )
看板Python
标题Re: [问题] lsit分割字串
时间Sat Sep 27 13:38:05 2014
※ 引述《healthlin (lin)》之铭言:
: 如果我有list是如下:
: ['t','t','f','t','t','t','f','t']
: 要如何遇到f就切割呢 要计算t的连续长度
: (这个例子是2,3,1)
: 谢谢
a = ['t','t','f','t','t','t','f','t']
b = "".join(a)
c = b.split('f')
c长这样 ['tt', 'ttt', 't']
map(len,c) 给出你要的 [2,3,1]
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 23.241.41.8
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1411796288.A.49D.html
※ 编辑: emind (23.241.41.8), 09/27/2014 13:40:32