0

I have a python list below. I would like to get the total count of all elements which are 1. The count needs to start once an element is 0. For example, in the list the count should be 3 as the first 0 is at index 2. Beyond this index, there are 3 instances of 1. The first two 1's should be ignored in the count.

mylist = [1, 1, 0, 1, 0, 0, 1, 1] 
AM_86
  • 115
  • 7
  • 3
    `mylist[mylist.index(0)+1:].count(1)` Note: will throw an exception if `0` is not in the list. – 001 Dec 15 '22 at 17:42

0 Answers0