compter des valeur consecutives en python

Solutions on MaxInterview for compter des valeur consecutives en python by the best coders in the world

showing results for - "compter des valeur consecutives en python"
Anouk
13 Jan 2017
1>>> from itertools import groupby
2>>> def groups(l):
3...     return [sum(g) for i, g in groupby(l) if i == 1]
4...
5>>> groups([0,1,0,0,0])
6[1]
7>>> groups([0,0,1,1,0])
8[2]
9>>> groups([1,1,0,1,1])
10[2, 2]
11
similar questions
queries leading to this page
compter des valeur consecutives en python