Guido van Rossum wrote:
I like your example because it matches the way I would have used generators to solve it. OTOH, it is not hard to rewrite parallel_reduce as a traditional function. In fact, the result is a bit shorter and quite a bit faster so it is not a good example of what you need generators for.
I'm not sure I understand. Maybe you meant to rewrite it as a class? There's some state that wouldn't have a good place to live without either a class or a (generator) stackframe to survive.
How about def parallel_reduce(items, funcs): items = iter(items) try: first = next(items) except StopIteration: raise TypeError accu = [first] * len(funcs) for b in items: accu = [f(a, b) for f, a in zip(funcs, accu)] return accu Peter