Re: best cumulative sum




"Peter Otten" <__peter__@xxxxxx> wrote in message
news:dm3uj4$kko$02$1@xxxxxxxxxxxxxxxxxxxx
> I'd rather have a second look whether the test is really needed.

That's too obscure of a hint.
Can you be a bit more explicit?
Here's an example (below).
You're saying I think that most of it is unnecessary.
Thanks,
Alan

def ireduce(func, iterable, init=None):
iterable = iter(iterable)
if init is None:
init = iterable.next()
yield init
else:
try:
first = iterable.next()
init = func(init, first)
yield init
except StopIteration:
yield init
for item in iterable:
init = func(init, item)
yield init


.