David Isaac wrote: > def ireduce(func, iterable, init=None): > if init is None: > iterable = iter(iterable) > init = iterable.next() > yield init > elif not iterable:
You are in for a surprise here: >>> def empty(): ... for item in []: ... yield item ... >>> bool(empty()) True >>> bool(iter([])) True # python 2.3 and probably 2.5 >>> bool(iter([])) False # python 2.4 > yield init > for item in iterable: > init = func(init, item) > yield init Peter -- http://mail.python.org/mailman/listinfo/python-list