code: def _accumulate(sequence, func):
      
      iterator = iter(sequence)
      total = next(iterator)
      yield total
      for element in iterator:
          total = func(total, element)
          yield total
docs: Python2 accumulate implementation taken from
      https://docs.python.org/3/library/itertools.html#itertools.accumulate