getting the index of starting and ending 1 of a binary list having a sequence of 0s or 1s
<p>I have a python list with binary information having either a sequence of 1s or a sequence of 0s for example:</p>

<pre><code>event = [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1]
</code></pre>

<p>How can I store the index values of the starting 1 and ending 1?</p>

<p>For example:</p>

<p>if <code>event = [0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1]</code> then <code>result = [2,5,8,11]</code></p>

<p><strong>EDIT2</strong> i realised that result should ideally be result_start=[2,8] result_end=[5,11], like lazyr solution, this way we understand where just a single 1 located. eg. event=[0,0,1,1,0,1], would yield a wrong list for the last 1. Thanks for trying all!</p>

<p><strong>EDIT1:</strong> I need the index of the first and the last 1 but first to the last 1.</p>

<p>I tried to code it like the following:</p>

<pre><code>k=False
j=0
result=[]
for i in event:
   if i==1:
       k=True
       result.append(k)
   else:
       k=False      
</code></pre>
