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
Post a Comment