code: def difference(iterable, func=sub):
      
      a, b = tee(iterable)
      try:
          item = next(b)
      except StopIteration:
          return iter([])
      return chain([item], map(lambda x: func(x[1], x[0]), zip(a, b)))
docs: By default, compute the first difference of *iterable* using
      :func:`operator.sub`.
  
          >>> iterable = [0, 1, 3, 6, 10]
          >>> list(difference(iterable))
          [0, 1, 2, 3, 4]
  
      This is the opposite of :func:`accumulate`'s default behavior:
  
          >>> from itertools import accumulate
          >>> iterable = [0, 1, 2, 3, 4]
          >>> list(accumulate(iterable))
          [0, 1, 3, 6, 10]
          >>> list(difference(accumulate(iterable)))
          [0, 1, 2, 3, 4]
  
      By default *func* is :func:`operator.sub`, but other functions can be
      specified. They will be applied as follows::
  
          A, B, C, D, ... --> A, func(B, A), func(C, B), func(D, C), ...
  
      For example, to do progressive division:
  
          >>> iterable = [1, 2, 6, 24, 120]  # Factorial sequence
          >>> func = lambda x, y: x // y
          >>> list(difference(iterable, func))
          [1, 2, 3, 4, 5]