title: Python List manipulation - couting common instances
body: <p>I have a ListA = [1,2,3,3,2,1,3,3,1,3]</p>
  <p>The 3s are in a sequence of 2,2,1 (2 instances, 2 instances, and 1 instance at the end)</p>
  <p>I want to generate a ListB = [2,2,1] from the above ListA</p>
  <p>I have code:</p>
  <pre><code>ls = [1,2,3,3,2,1,3,3,2,3]
  
  pplist = []
  pp = 0
  for ii in range(0,len(ls)):
      if ls[ii] == 3:
          pp += 1
          
      else:
          if pp &gt; 0:
              pplist.append(pp)
              pp = 0
  
  print(pplist)
  </code></pre>
  <p>This gives me [2,2] and for the last element I have to add an additional if-loop.
  Is there a way to achieve this without having additional code just for the last element?</p>
  <p>(ListA could also end with multiple 3s instead of a single 3)</p>
  <p>Thank you</p>
  <p>R</p>