title: how to count consecutive duplicates in a python list
body: <p>I have a list as follows, consisting of only (-1)s and 1s:</p>
  
  <pre><code>list1=[-1,-1,1,1,1,-1,1]
  </code></pre>
  
  <p>I'm trying to append the number of consecutive duplicates into a list, e.g.:</p>
  
  <pre><code>count_dups=[2,3,1,1] 
  </code></pre>
  
  <p>I've tried creating a new list and using the zip function as the first step, but 
  can't seem to go on because of the cut-off end-value</p>
  
  <pre><code>list2=list1[1:]
  empty=[]
  for x,y in zip(list1,list2):
      if x==y:
          empty.append(x)
      else:
          empty.append(0)
  </code></pre>