"Michael Spencer" <[EMAIL PROTECTED]> wrote in message
news:mailman.1054.1132707811.18701.python-> This can be written more
concisely as a generator:
>
> >>> import operator
> >>> def ireduce(func, iterable, init):
> ... for i in iterable:
> ... init = func(init, i)
> ... yield init
OK, this might do it. But is a generator "better"?
(I assume accuracy is the same, so what about speed?)
def ireduce(func, iterable, init=None):
if not init:
iterable = iter(iterable)
init = iterable.next()
yield init
elif not iterable:
yield init
for item in iterable:
init = func(init, item)
yield init
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list