def accumulate(iterable, func=operator.add):
 it = iter(iterable)
 total = next(it)
 (yield total)
 for element in it:
  total = func(total, element)
  (yield total)

def accumulate ( iterable , func = operator . add ) : it = iter ( iterable ) total = next ( it ) ( yield total ) for element in it : total = func ( total , element ) ( yield total )
return running totals .