title: Reduce increments in array values to 1
body: <p>I am trying to create a list (say <code>B</code>) which increments only when there is a difference in values of another list (say <code>A</code>), for example:</p>
  
  <p><code>[1,1,2,2,4,4]</code> to <code>[0,0,1,1,2,2]</code> or</p>
  
  <p><code>[1,1,1,1,4,4,4,4]</code> to <code>[0,0,0,0,1,1,1,1]</code> etc.</p>
  
  <p>The following code does it:</p>
  
  <pre><code>boxes=[1,1,1,1,4,4,4,4]
  positions=[0]
  position=0
  for psn,box in list(enumerate(boxes))[:-1]:
      if boxes[psn+1]-box ==0:
          increment=0
      else:
          increment=1
      position=position+increment
      positions.append(position)
  print(positions)
  </code></pre>
  
  <p>Can anybody give suggestions to do it using list comprehensions (preferable using <code>lambda</code> functions)?</p>