python - Replacing a string with counts of streaks -


let's have string of following form:

"000000111100011100001011000000001111" 

and want create list containing lengths of 1-streaks:

[4, 3, 1, 2, 4] 

is there nice one-liner this?

if don't mind from itertools import groupby...

>>> itertools import groupby >>> [len(list(g)) k, g in groupby(s) if k == '1'] [4, 3, 1, 2, 4] 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -