Re: best cumulative sum
- From: "David Isaac" <aisaac0@xxxxxxxxxxx>
- Date: Thu, 24 Nov 2005 16:08:02 GMT
"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
.
- Follow-Ups:
- Re: best cumulative sum
- From: Peter Otten
- Re: best cumulative sum
- References:
- best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Micah Elliott
- Re: best cumulative sum
- From: Erik Max Francis
- Re: best cumulative sum
- From: bonono@xxxxxxxxx
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Colin J. Williams
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Michael Spencer
- Re: best cumulative sum
- From: bonono@xxxxxxxxx
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Peter Otten
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Peter Otten
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Peter Otten
- best cumulative sum
- Prev by Date: Re: Writing big XML files where beginning depends on end.
- Next by Date: Re: Why are there no ordered dictionaries?
- Previous by thread: Re: best cumulative sum
- Next by thread: Re: best cumulative sum
- Index(es):