code: def collapse_equal_values(values, counts):
      
      assert len(values) == len(counts)
      previousValue = values[0]
      previousCount = 0
  
      for value, count in zip(values, counts):
          if value != previousValue:
              yield (previousValue, previousCount)
              previousCount = 0
              previousValue = value
          previousCount += count
  
      yield (previousValue, previousCount)
docs: Take a tuple (values, counts), remove consecutive values and increment their count instead.