count consecutive values in python

#count consecutif 1 in list. list exemple l=['1','1','0','1','0','1,'1',1']
    for i in ch:
        if i=='1':
            cpt +=1

Here is what the above code is Doing:
1. Initialize a counter variable cpt to 0.
2. Initialize an empty list compte.
3. Iterate through the list ch.
4. If the element is 1, increment the counter variable cpt by 1.
5. If the element is 0, append the value of cpt to the list compte and reset cpt to 0.
6. After the iteration is complete, append the value of cpt to the list compte.

The list compte will now contain the count of consecutive 1’s in the list ch.

You can find the maximum value in the list compte using the max() function.