DEV Community

Discussion on: Day-4 Maximum Consecutive Ones

Collapse
 
paddy3118 profile image
Paddy3118 • Edited

"find the length of the maximum runs/groups of ones in a list"

Groups means check groupby for me and I came up with the following

from itertools import groupby

def answer(lst):
    return len(max(tuple(g) for k, g in groupby(lst)
                            if k == 1))

print(answer([1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]))

Which returns 3.