create sub lists by grouping with conditional check on two consecutive zeros
<p>I have a list:</p>

<pre><code>lst = [0, -7, 0, 0, -8, 0, 0, -4, 0, 0, 0, -6, 0, -4, -29, -10, 0, -16, 0, 0, 2, 3, 0, 18, -1, -2, 0, 0, 0, 0, 0, 0, 21, 10, -10, 0, -12, 3, -5, -10]
</code></pre>

<p>I want to create group of sublists with conditional break when a value is followed by two consecutive zeros.</p>

<p>so my intermediate list would like </p>

<pre><code>newlst = [-7,-8,-4,[-6,-4,-29,-10,-16],[2,3,18,-1,-2],[21,10,-10,-12,3,-5,-10]]
</code></pre>

<p>whereas the final output will be sum of sublists:</p>

<pre><code>[-7,-8,-4,-65,18,-3]
</code></pre>

<p>I tried using the index number in a for loop with enumerate but i'm not getting my desired output.</p>

<pre><code>list = lst = [0, -7, 0, 0, -8, 0, 0, -4, 0, 0, 0, -6, 0, -4, -29, -10, 0, -16, 0, 0, 2, 3, 0, 18, -1, -2, 0, 0, 0, 0, 0, 0, 21, 10, -10, 0, -12, 3, -5, -10]
lastElement = None
new_list=[]
sub_list=[]
for element in list:
    if element == 0 == lastElement:
        if sub_list == []:
            continue
        new_list.append(sub_list)
        sub_list = []
    elif element == 0:
        pass
    else:
        sub_list.append(element)
    lastElement = element
new_list.append(sub_list)
print(new_list)
[[-7], [-8], [-4], [-6, -4, -29, -10, -16], [2, 3, 18, -1, -2], [21, 10, -10, -12, 3, -5, -10]]
</code></pre>

python python-2.7